fix: ensure the modal closed by level (#24984)

This commit is contained in:
17hz 2025-09-02 17:06:10 +08:00 committed by GitHub
parent af88266212
commit af351b1723
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 15 additions and 0 deletions

View File

@ -2,6 +2,7 @@ import type { FC } from 'react'
import {
memo,
useCallback,
useEffect,
useMemo,
useRef,
} from 'react'
@ -188,6 +189,20 @@ const ModelModal: FC<ModelModalProps> = ({
return null
}, [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 (
<PortalToFollowElem open>
<PortalToFollowElemContent className='z-[60] h-full w-full'>