feat: add keyboard shortcuts support for dialog confirmation (#15752)

This commit is contained in:
诗浓 2025-03-13 21:42:53 +08:00 committed by GitHub
parent 49c952a631
commit e796937d02
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -46,13 +46,17 @@ function Confirm({
const handleKeyDown = (event: KeyboardEvent) => {
if (event.key === 'Escape')
onCancel()
if (event.key === 'Enter' && isShow) {
event.preventDefault()
onConfirm()
}
}
document.addEventListener('keydown', handleKeyDown)
return () => {
document.removeEventListener('keydown', handleKeyDown)
}
}, [onCancel])
}, [onCancel, onConfirm, isShow])
const handleClickOutside = (event: MouseEvent) => {
if (maskClosable && dialogRef.current && !dialogRef.current.contains(event.target as Node))