antd-record-hotkey-input
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

antd-record-hotkey-input

Ant Design 快捷键录制输入框

NPM version NPM downloads install size

Install

npm i antd-record-hotkey-input -S

Usage

import { Empty, message } from 'antd';
import RecordShortcutInput from 'antd-record-hotkey-input';
import { useState } from 'react';
import { useHotkeys } from 'react-hotkeys-hook';

const App = () => {
  const [shortcut, setShortcut] = useState('');

  const shortRef = useHotkeys<HTMLDivElement>(
    shortcut,
    () => {
      message.success('快捷键触发');
    },
    {
      preventDefault: true,
    },
  );

  return (
    <>
      <RecordShortcutInput
        style={{ width: 500 }}
        defaultValue={shortcut}
        onConfirm={(value) => {
          console.log('快捷键变更为:', value);
          setShortcut(value);
        }}
      />

      <div tabIndex={-1} className="container" ref={shortRef}>
        {shortcut ? <span>点击聚焦,测试快捷键:{shortcut}</span> : <Empty />}
      </div>
    </>
  );
};

export default App;

Package Sidebar

Install

npm i antd-record-hotkey-input

Weekly Downloads

15

Version

1.1.0

License

MIT

Unpacked Size

57.3 kB

Total Files

38

Last publish

Collaborators

  • wxh16144