feat: add keyboard shortcuts support for dialog confirmation (#15752)
This commit is contained in:
parent
49c952a631
commit
e796937d02
@ -46,13 +46,17 @@ function Confirm({
|
|||||||
const handleKeyDown = (event: KeyboardEvent) => {
|
const handleKeyDown = (event: KeyboardEvent) => {
|
||||||
if (event.key === 'Escape')
|
if (event.key === 'Escape')
|
||||||
onCancel()
|
onCancel()
|
||||||
|
if (event.key === 'Enter' && isShow) {
|
||||||
|
event.preventDefault()
|
||||||
|
onConfirm()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener('keydown', handleKeyDown)
|
document.addEventListener('keydown', handleKeyDown)
|
||||||
return () => {
|
return () => {
|
||||||
document.removeEventListener('keydown', handleKeyDown)
|
document.removeEventListener('keydown', handleKeyDown)
|
||||||
}
|
}
|
||||||
}, [onCancel])
|
}, [onCancel, onConfirm, isShow])
|
||||||
|
|
||||||
const handleClickOutside = (event: MouseEvent) => {
|
const handleClickOutside = (event: MouseEvent) => {
|
||||||
if (maskClosable && dialogRef.current && !dialogRef.current.contains(event.target as Node))
|
if (maskClosable && dialogRef.current && !dialogRef.current.contains(event.target as Node))
|
||||||
|
Loading…
Reference in New Issue
Block a user