+
My HotKeys are effective here
- { this.props.children }
+ {this.props.children}
- )
+ );
}
}
const MyHotKeysComponent = withHotKeys(MyComponent);
const keyMap = {
- TEST: 't'
+ TEST: "t"
};
const handlers = {
- TEST: ()=> console.log('Test')
+ TEST: () => console.log("Test")
};
-
-
- You can press 't' to log to the console.
-
-
+
+ You can press 't' to log to the console.
+;
```
### Pre-defining default prop values
@@ -538,7 +519,7 @@ You can use the second argument of `withHotKeys` to specify default values for a
> If you do provide prop values when you render the component, these will be merged with (and override) those defined in the second argument of `withHotKeys`.
```javascript
-import {withHotKeys} from 'react-hotkeys';
+import { withHotKeys } from "react-hotkeys";
class MyComponent extends Component {
render() {
@@ -546,36 +527,34 @@ class MyComponent extends Component {
* Must unwrap hotKeys prop and pass its values to a DOM-mountable
* element (like the div below).
*/
- const {hotKeys, ...remainingProps} = this.props;
+ const { hotKeys, ...remainingProps } = this.props;
return (
-
+
My HotKeys are effective here
- { this.props.children }
+ {this.props.children}
- )
+ );
}
}
const keyMap = {
- TEST: 't'
+ TEST: "t"
};
const handlers = {
- TEST: ()=> console.log('Test')
+ TEST: () => console.log("Test")
};
-const MyHotKeysComponent = withHotKeys(MyComponent, {keyMap, handlers});
+const MyHotKeysComponent = withHotKeys(MyComponent, { keyMap, handlers });
/**
* Render without having to specify prop values
*/
-
- You can press 't' to log to the console.
-
-
+
You can press 't' to log to the console.
+;
```
## GlobalHotKeys component
@@ -583,10 +562,10 @@ const MyHotKeysComponent = withHotKeys(MyComponent, {keyMap, handlers});
`
` components match key events that occur anywhere in the document (even when no part of your React application is in focus).
```javascript
-const keyMap = { SHOW_ALL_HOTKEYS: 'shift+?' };
+const keyMap = { SHOW_ALL_HOTKEYS: "shift+?" };
const handlers = { SHOW_ALL_HOTKEYS: this.showHotKeysDialog };
-
+;
```
`` generally have no need for children, so should use a self-closing tag (as shown above). The only exception is when you are nesting other `` components somewhere in the descendents (these are mounted before their parents, and so are generally matched first).
@@ -606,7 +585,6 @@ It is recommended to use `` components whenever possible for better per
The GlobalHotKeys component provides a declarative and native JSX syntax for defining hotkeys that are applicable beyond you React application.
```javascript
-
-
- /**
- * Wraps all children in a DOM-mountable component
- */
- { children }
-
+>
+ /** * Wraps all children in a DOM-mountable component */
+ {children}
```
@@ -699,14 +671,12 @@ If this is not what you want for your application, you can modify the list of ta
If you want `react-hotkeys` to ignore key events coming from a particular area of your app when it is in focus, you can use the `` component:
```javascript
-import {HotKeysIgnore} from 'react-hotkeys';
+import { HotKeysIgnore } from "react-hotkeys";
- /**
- * Children that, when in focus, should have its key events ignored by
- * react hotkeys
- */
-
+ /** * Children that, when in focus, should have its key events ignored by *
+ react hotkeys */
+;
```
### HotKeysIgnore component API
@@ -747,7 +717,7 @@ By default, `` will ignore all key events, but you can customiz
Similar to the ``'s `withHotKeys()` function, there is a `withHotKeysIgnore()` function for achieving the `` functionality, without the need for rendering a surrounding DOM-mountable element.
```javascript
-import {withHotKeysIgnore} from 'react-hotkeys';
+import { withHotKeysIgnore } from "react-hotkeys";
class MyComponent extends Component {
render() {
@@ -755,31 +725,29 @@ class MyComponent extends Component {
* Must unwrap hotKeys prop and pass its values to a DOM-mountable
* element (like the div below).
*/
- const {hotKeys, ...remainingProps} = this.props;
+ const { hotKeys, ...remainingProps } = this.props;
return (
-
+
HotKeys ignores key events from here
- { this.props.children }
+ {this.props.children}
- )
+ );
}
}
const MyHotKeysComponent = withHotKeysIgnore(MyComponent);
-
-
- All key events except the 'Escape' key are ignored here
-
-
+
+ All key events except the 'Escape' key are ignored here
+;
```
`withHotKeysIgnore()` also accepts a second argument that becomes the default props of the component it returns:
```javascript
-import {withHotKeysIgnore} from 'react-hotkeys';
+import { withHotKeysIgnore } from "react-hotkeys";
class MyComponent extends Component {
render() {
@@ -787,28 +755,25 @@ class MyComponent extends Component {
* Must unwrap hotKeys prop and pass its values to a DOM-mountable
* element (like the div below).
*/
- const {hotKeys, ...remainingProps} = this.props;
+ const { hotKeys, ...remainingProps } = this.props;
return (
-
+
HotKeys ignores key events from here
- { this.props.children }
+ {this.props.children}
- )
+ );
}
}
-const MyHotKeysComponent = withHotKeysIgnore(MyComponent, { except: 'Escape' });
+const MyHotKeysComponent = withHotKeysIgnore(MyComponent, { except: "Escape" });
-
- All key events except the 'Escape' key are ignored here
-
-
+
All key events except the 'Escape' key are ignored here
+;
```
-
## Allowing hotkeys and handlers props to change
For performance reasons, by default `react-hotkeys` takes the `keyMap` and `handlers` prop values when `
` components are focused and when `` components are mounted. It ignores all subsequent updates
@@ -922,7 +887,7 @@ configure({
You have 3 options:
1. Use the [`component` prop](#HotKeys-component-API) to specify a `span` or some other alternative DOM-mountable component to wrap your component in, each time you render a component you don't want to wrap in a div element.
-1. Use the [`defaultComponent` configuration option](#Configuration) to specify a `span` or some other alternative DOM-mountable component to wrap *all* `` children in.
+1. Use the [`defaultComponent` configuration option](#Configuration) to specify a `span` or some other alternative DOM-mountable component to wrap _all_ `` children in.
1. Use the [withHotKeys HoC API](#withHotKeys-HoC-API) to avoid rendering a wrapping component at all.
#### Other keyboard event listeners are no longer being triggered
@@ -937,7 +902,7 @@ Check that you are [correctly passing the hotKeys props to a DOM-mountable compo
Make sure you are focusing a descendant of the `` component before you press the keys.
-Check that the `` component that defines the handler is also an ancestor of the focused component, and is above (or *is*) the component that defines the `handlers`.
+Check that the `` component that defines the handler is also an ancestor of the focused component, and is above (or _is_) the component that defines the `handlers`.
Also make sure your React application is not calling `stopPropagation()` on the key events before they reach the `` component that defines the `keyMap`.
@@ -951,7 +916,7 @@ This can be disabled using CSS similar to the following:
```css
div[tabindex="-1"]:focus {
- outline: 0;
+ outline: 0;
}
```
@@ -965,14 +930,14 @@ You can set the logging level using the `logLevel` [configuration option](#Confi
For performance reasons, only some of the log levels are available in the production build. You will need to use the development build to get the full log output.
-| Log Level | Severity | Description | Available in Dev | Available in Prod |
-| :-- | :-- | :-- | :-- | :-- |
-| verbose | (highest) | `debug` + internal data representations | Yes | No |
-| debug | | `info` + event propagation info | Yes | No |
-| info | | `warn` + general info | Yes | No |
-| warn | (default) | `error` + warnings | Yes | Yes |
-| error | | Errors only (ignore warnings) | Yes | Yes |
-| none | (lowest) | Log nothing | Yes | Yes |
+| Log Level | Severity | Description | Available in Dev | Available in Prod |
+| :-------- | :-------- | :-------------------------------------- | :--------------- | :---------------- |
+| verbose | (highest) | `debug` + internal data representations | Yes | No |
+| debug | | `info` + event propagation info | Yes | No |
+| info | | `warn` + general info | Yes | No |
+| warn | (default) | `error` + warnings | Yes | Yes |
+| error | | Errors only (ignore warnings) | Yes | Yes |
+| none | (lowest) | Log nothing | Yes | Yes |
Logs appear in the developer console of the browser.
@@ -984,7 +949,6 @@ Each line is prefixed with (where applicable):
Each id is also given a coloured emoticon, to make it easy to visually trace the propagation of particular events through multiple components.
-
## Optimizations
`react-hotkeys` uses a lot of optimizations to help keep it as performant as possible (both in terms of time and memory). It can be helpful to be aware of some of these measures if you are seeing unexpected behaviour:
@@ -1015,7 +979,6 @@ If you believe you have found a bug or have a feature request, please [open an i
`react-hotkeys` is considered stable and already being widely used (most notably Lystable and Whatsapp).
-
## Contribute, please!
If you're interested in helping out with the maintenance of `react-hotkeys`, make yourself known on [Gitter](https://gitter.im/Chrisui/react-hotkeys), [open an issue](https://github.com/greena13/react-hotkeys/issues) or create a pull request.
@@ -1026,10 +989,10 @@ Collaboration is loosely being coordinated across [Gitter](https://gitter.im/Chr
### Using GitHub Issues
-* Use the search feature to check for an existing issue
-* Include as much information as possible and provide any relevant resources (Eg. screenshots)
-* For bug reports ensure you have a reproducible test case
- * A pull request with a breaking test would be super preferable here but isn't required
+- Use the search feature to check for an existing issue
+- Include as much information as possible and provide any relevant resources (Eg. screenshots)
+- For bug reports ensure you have a reproducible test case
+ - A pull request with a breaking test would be super preferable here but isn't required
### Submitting a Pull Request
@@ -1045,42 +1008,42 @@ Collaboration is loosely being coordinated across [Gitter](https://gitter.im/Chr
All build commands are included in the `package.json`:
-| Command | Description |
-|:--|:--|
-| `yarn prepublish` | Build all bundles using babel and rollup |
-| `yarn build-cjs` | Build the development and production CommonJS bundles using babel and rollup, respectively |
-| `yarn build-es` | Build the development and production ES6 bundles using babel and rollup, respectively |
-| `yarn build-umd` | Build the development and production UMD bundles using rollup |
-| `yarn build-development` | Build the development CommonJS bundle using babel |
-| `yarn build-es-development` | Build the development ES6 bundle using babel |
-| `yarn build-umd-development` | Build the development ES6 bundle using rollup |
-| `yarn build-production` | Build the production CommonJS bundle using rollup |
-| `yarn build-es-production` | Build the production ES6 bundle using rollup |
-| `yarn build-umd-production` | Build the production ES6 bundle using rollup |
+| Command | Description |
+| :--------------------------- | :----------------------------------------------------------------------------------------- |
+| `yarn prepublish` | Build all bundles using babel and rollup |
+| `yarn build-cjs` | Build the development and production CommonJS bundles using babel and rollup, respectively |
+| `yarn build-es` | Build the development and production ES6 bundles using babel and rollup, respectively |
+| `yarn build-umd` | Build the development and production UMD bundles using rollup |
+| `yarn build-development` | Build the development CommonJS bundle using babel |
+| `yarn build-es-development` | Build the development ES6 bundle using babel |
+| `yarn build-umd-development` | Build the development ES6 bundle using rollup |
+| `yarn build-production` | Build the production CommonJS bundle using rollup |
+| `yarn build-es-production` | Build the production ES6 bundle using rollup |
+| `yarn build-umd-production` | Build the production ES6 bundle using rollup |
### Development builds
-| Bundle | Transpiled with | Modularized with | Output |
-|:-- |:-- |:-- |:-- |
-| CommonJS | Babel | Babel | /cjs/index.js |
-| UMD | Babel | Rollup | /umd/index.js |
-| ES6 | Babel | Babel | /es/index.js |
+| Bundle | Transpiled with | Modularized with | Output |
+| :------- | :-------------- | :--------------- | :------------ |
+| CommonJS | Babel | Babel | /cjs/index.js |
+| UMD | Babel | Rollup | /umd/index.js |
+| ES6 | Babel | Babel | /es/index.js |
### Production builds
-| Bundle | Transpiled with | Optimized with | Minified with | Output |
-|:-- |:-- |:-- |:-- | :-- |
-| CommonJS | Babel | Rollup | Uglify | cjs/react-hotkeys.production.min.js |
-| UMD | Babel | Rollup | Uglify | /umd/react-hotkeys.min.js |
-| ES6 | Babel | Rollup | Babel-minify | /es/react-hotkeys.production.min.js |
+| Bundle | Transpiled with | Optimized with | Minified with | Output |
+| :------- | :-------------- | :------------- | :------------ | :---------------------------------- |
+| CommonJS | Babel | Rollup | Uglify | cjs/react-hotkeys.production.min.js |
+| UMD | Babel | Rollup | Uglify | /umd/react-hotkeys.min.js |
+| ES6 | Babel | Rollup | Babel-minify | /es/react-hotkeys.production.min.js |
### Build configuration
To understand the configuration for any one build, you need to consult 3 places:
-* The CLI arguments used in the `scripts` of `package.json`
-* The `.babelrc` file (match the env to the `BABEL_ENV` value set in `scripts` above)
-* The `rollup.configs.js` (if applicable)
+- The CLI arguments used in the `scripts` of `package.json`
+- The `.babelrc` file (match the env to the `BABEL_ENV` value set in `scripts` above)
+- The `rollup.configs.js` (if applicable)
## Authorship