diff --git a/packages/hooks/src/useKeyPress/demo/demo9.tsx b/packages/hooks/src/useKeyPress/demo/demo9.tsx index f4852d9597..050260923a 100644 --- a/packages/hooks/src/useKeyPress/demo/demo9.tsx +++ b/packages/hooks/src/useKeyPress/demo/demo9.tsx @@ -4,11 +4,12 @@ import { Switch } from 'antd'; export default () => { const [counter, setCounter] = useState(0); - const [observe, { toggle }] = useBoolean(); + const [observe, { toggle }] = useBoolean(true); + useKeyPress( - 'uparrow', + 'w', () => { - setCounter((s) => s + 1); + setCounter((prev) => prev + 1); }, { observe, @@ -21,7 +22,7 @@ export default () => { Switch observe state   -
Press ArrowUp by key to increase when observe state is checked
+
Press [w] to increase when observe state is checked
counter: {counter}
diff --git a/packages/hooks/src/useKeyPress/index.en-US.md b/packages/hooks/src/useKeyPress/index.en-US.md index 2881871456..91f871a930 100644 --- a/packages/hooks/src/useKeyPress/index.en-US.md +++ b/packages/hooks/src/useKeyPress/index.en-US.md @@ -70,7 +70,7 @@ useKeyPress( | target | DOM element or ref | `() => Element` \| `Element` \| `MutableRefObject` | - | | exactMatch | Exact match. If set `true`, the event will only be trigger when the keys match exactly. For example, pressing [shift + c] will not trigger [c] | `boolean` | `false` | | useCapture | to block events bubbling | `boolean` | `false` | -| observe | to control the observe state. If set `true`, the event will be trigger when the element is in focus. | `boolean` | `true` | +| observe | to control the observe state. If set `false`, the callback will not be triggered. | `boolean` | `true` | ## Remarks diff --git a/packages/hooks/src/useKeyPress/index.zh-CN.md b/packages/hooks/src/useKeyPress/index.zh-CN.md index fd15c48b43..488ebf7757 100644 --- a/packages/hooks/src/useKeyPress/index.zh-CN.md +++ b/packages/hooks/src/useKeyPress/index.zh-CN.md @@ -70,7 +70,7 @@ useKeyPress( | target | DOM 节点或者 ref | `() => Element` \| `Element` \| `MutableRefObject` | - | | exactMatch | 精确匹配。如果开启,则只有在按键完全匹配的情况下触发事件。比如按键 [shift + c] 不会触发 [c] | `boolean` | `false` | | useCapture | 是否阻止事件冒泡 | `boolean` | `false` | -| observe | 控制监听状态 为 false 时不会触发任何事件 | `boolean` | `true` | +| observe | 是否开启监听状态,为 false 时不会触发回调函数 | `boolean` | `true` | ## Remarks