Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

keyboard-shortcut-component

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

keyboard-shortcut-component

A React component that fires a callback when a hotkey combination is pressed

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
38
decreased by-32.14%
Maintainers
1
Weekly downloads
 
Created
Source

KeyboardShortcut Component

tests GitHub

A handy React component that listens for keyboard combinations (hotkeys) when mounted.

Getting Started

Install

npm install keyboard-shortcut-component

Usage

Render <KeyboardShortcut /> component when you want to listen to keyboard shortcuts:

import { KeyboardShortcut } from 'keyboard-shortcut-component';

export function Component() {
  const [showDialog, setShowDialog] = useState(false);
  const openDialog = () => setShowDialog(true);
  const closeDialog = () => setShowDialog(false);
  return (
    <>
      <KeyboardShortcut combination="shift+k" onKeyDown={openDialog} />
      {showDialog ? (
        <>
          <KeyboardShortcut combination="esc" onKeyDown={closeDialog} />
          <SomeDialog />
        </>
      ) : null}
    </>
  );
}

API

<KeyboardShortcut
  combination="alt+shift+space"
  onKeyDown={(event: KeyboardEvent, combination: string) => void}
  disabled={false}
/>

Props

interface Props {
  combination: string;
  onKeyDown: (event: KeyboardEvent, combination: string) => void;
  disabled?: boolean;
}

Credits

This library uses the awesome minimalistic is-hotkey package under the hood.

Keywords

FAQs

Package last updated on 05 Dec 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc