Browse Source

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

诗浓 1 tháng trước cách đây
mục cha
commit
e796937d02
1 tập tin đã thay đổi với 5 bổ sung1 xóa
  1. 5 1
      web/app/components/base/confirm/index.tsx

+ 5 - 1
web/app/components/base/confirm/index.tsx

@@ -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))