1.1.0 • Published 2 years ago

react-keyevent v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

React Keyevent

npm version npm versionnpm version npm version npm version npm version

An easy-to-use keyboard event react component, Can achieve a variety of custom keyboard functions, Package size less than 3kb

非常容易使用的一个键盘事件监听react组件,可实现各种自定义快捷键功能,只有不到3kb

repository-open-graph-template副本

Repository

https://github.com/yuanguandong/react-keyevent

Live demo

https://react-keyevent.netlify.app/

https://yuanguandong.github.io/react-keyevent/

Live code

npm.io

Install

npm i react-keyevent -S

How to use

import React, { useState } from "react";
import Keyevent from "react-keyevent";

const TopSide = () => {
  const [count, setCount] = useState(0);
  const onAltT = () => {
    setCount(count + 1);
  };
  return (
    <Keyevent
      className="TopSide"
      events={{
        onAltT,
      }}
      needFocusing
    >
      <span className="tip">Click To Focusing</span>
      <div className="group">
        <span className="key">Alt</span>
        <span className="key">T</span>
        <span className="count">{count}</span>
      </div>
    </Keyevent>
  );
};
export default TopSide

Props

propertyrequiredtypedefaultValuedescription
eventstrue{ key: string: (e: KeyboardEvent) => void }nullThe binding keyboard events 绑定的键盘事件
needFocusingfalsebooleanfalse是否需要聚焦,若值为true,则需要聚焦Focus这个容器组件(点击)