fix: ensure the modal closed by level (#24984)
This commit is contained in:
parent
af88266212
commit
af351b1723
1 changed files with 15 additions and 0 deletions
|
|
@ -2,6 +2,7 @@ import type { FC } from 'react'
|
||||||
import {
|
import {
|
||||||
memo,
|
memo,
|
||||||
useCallback,
|
useCallback,
|
||||||
|
useEffect,
|
||||||
useMemo,
|
useMemo,
|
||||||
useRef,
|
useRef,
|
||||||
} from 'react'
|
} from 'react'
|
||||||
|
|
@ -188,6 +189,20 @@ const ModelModal: FC<ModelModalProps> = ({
|
||||||
return null
|
return null
|
||||||
}, [model, provider])
|
}, [model, provider])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const handleKeyDown = (event: KeyboardEvent) => {
|
||||||
|
if (event.key === 'Escape') {
|
||||||
|
event.stopPropagation()
|
||||||
|
onCancel()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
document.addEventListener('keydown', handleKeyDown, true)
|
||||||
|
return () => {
|
||||||
|
document.removeEventListener('keydown', handleKeyDown, true)
|
||||||
|
}
|
||||||
|
}, [onCancel])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PortalToFollowElem open>
|
<PortalToFollowElem open>
|
||||||
<PortalToFollowElemContent className='z-[60] h-full w-full'>
|
<PortalToFollowElemContent className='z-[60] h-full w-full'>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue