
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
react-keybinding
Advanced tools
Declarative, lightweight, and robust keybindings mixin for React.
'⌘S'
string syntax for declaring bindingskeybinding
method of that component'⌘S'
on Mac to '^S'
on Windows)Install with npm and use in your React projects with either browserify or webpack.
$ npm install react-keybinding
var React = require('react'),
Keybinding = require('../');
var HelloMessage = React.createClass({
mixins: [Keybinding],
keybindingsPlatformAgnostic: true,
keybindings: {
'⌘S': function(e) {
console.log('save!');
e.preventDefault();
},
'⌘C': 'COPY'
},
keybinding: function(event, action) {
// event is the browser event, action is 'COPY'
console.log(arguments);
},
render: function() {
return React.createElement("div", null, "Hello");
}
});
React.render(React.createElement(HelloMessage, {name: "John"}), document.body);
There's a runnable example in the ./examples
directory: to run it,
$ npm install
$ cd example
$ npm install
$ npm start
See tmcw/ditty for an example of react-keybinding in an application.
This module exposes a single mixin called Keybinding
.
Where you use this mixin on Components, it expects a property called
keybindings
of the format:
keybindings: {
// keys are strings: they can contain meta and shift symbols,
// numbers, strings, etc
'⌘S': function(e) {
// bindings can map to functions that they call directly
},
// or to constants that are passed to the component's
// 'keybinding' method.
'⌘C': 'COPY'
}
Platform agnostic keybindings will automatically listen for the 'Ctrl'
equivalent of 'Cmd'
keybindings, and vice-versa. To automatically coerce
platform specific keybindings, provide a property called
keybindingsPlatformAgnostic
of the format:
keybindingsPlatformAgnostic: true,
keybindings: { ... }
The mixin provides a method for components called .getAllKeybindings()
:
this yields an array of all keybindings
properties on all active components.
The full range of codes and modifiers supported is listed in SYNTAX.md.
$ npm test
FAQs
declarative, concise keybindings for react
The npm package react-keybinding receives a total of 1,596 weekly downloads. As such, react-keybinding popularity was classified as popular.
We found that react-keybinding demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 43 open source maintainers collaborating on the project.
Did you know?
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.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.