Skip to content

Commit

Permalink
fix: move HelpDialog outside of Popover to ensure proper behavior
Browse files Browse the repository at this point in the history
The `HelpDialog` component was previously nested inside the `Popover`, leading to unexpected behavior when attempting to close the dialog. By moving the `HelpDialog` component outside the `Popover`, the components no longer interfere with each other in the DOM tree, resolving the issue.
  • Loading branch information
liby authored and NWYLZW committed Aug 11, 2023
1 parent e86c2b9 commit 986ca83
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
19 changes: 3 additions & 16 deletions core/src/components/bottom-status/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import './index.scss'

import React, { useContext, useEffect, useRef, useState } from 'react'
import React, { useContext, useEffect, useState } from 'react'

import { isMacOS } from '../../utils'
import type { DialogRef } from '../Dialog.tsx'
import { HelpDialog } from '../editor-zone/HelpDialog.tsx'
import { Help } from '../editor-zone/Help.tsx'
import { MonacoScopeContext } from '../EditorZone.tsx'
import { Popover } from '../Popover.tsx'

Expand All @@ -16,7 +14,6 @@ const prefix = 'ppd-bottom-status'
export function BottomStatus() {
const { editorInstance } = useContext(MonacoScopeContext) ?? {}

const helpDialogRef = useRef<DialogRef>(null)

const [[line, column], setLineAndColumn] = useState<[number, number]>([0, 0])
useEffect(() => {
Expand All @@ -30,17 +27,7 @@ export function BottomStatus() {
updateLineAndColumn()
}, [editorInstance])
return <div className={`monaco-editor ${prefix}`}>
<Popover
style={{ cursor: 'pointer' }}
offset={[0, 3]}
content={<>
Find Help(<code>{isMacOS ? '^' : 'Ctrl'}</code> + <code>/</code>)
</>}
onClick={() => helpDialogRef.current?.open()}
>
<HelpDialog ref={helpDialogRef} />
<div className='cldr codicon codicon-info' />
</Popover>
<Help />
<History />
<TypescriptVersionStatus />
<Popover style={{ cursor: 'pointer' }}
Expand Down
27 changes: 27 additions & 0 deletions core/src/components/editor-zone/Help.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { useRef } from 'react'

import { isMacOS } from '../../utils'
import type { DialogRef } from '../Dialog.tsx'
import { Popover } from '../Popover.tsx'

import { HelpDialog } from './HelpDialog.tsx'

export function Help() {
const helpDialogRef = useRef<DialogRef>(null)

return (
<>
<HelpDialog ref={helpDialogRef} />
<Popover
style={{ cursor: 'pointer' }}
offset={[0, 3]}
content={<>
Find Help(<code>{isMacOS ? '^' : 'Ctrl'}</code> + <code>/</code>)
</>}
onClick={() => helpDialogRef.current?.open()}
>
<div className='cldr codicon codicon-info' />
</Popover>
</>
)
}

0 comments on commit 986ca83

Please sign in to comment.