fix: ensure the modal closed by level (#24984)
This commit is contained in:
@@ -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'>
|
||||||
|
Reference in New Issue
Block a user