1.0.0 • Published 7 years ago
@daniel.husar/on-enter-or-space v1.0.0
on-enter-or-space
Execute function for enter and space keyboard events. This is usefull if you want to make your app accessible, and you want to add keyboard navigation to the components that have onClick handlers.
Install
Using npm
npm install @daniel.husar/on-enter-or-spaceUsing yarn
yarn add @daniel.husar/on-enter-or-spaceUsage with react
First time you call onEnterOrSpace(callback) it will return another function, that accepts event object. If the event object was enter or space, it will call the callback with event object as parameter.
import onEnterOrSpace from '@daniel.husar/on-enter-or-space';
const component = (props) => {
return <span onClick={props.handleOnClick} onKeyDown={onEnterOrSpace(props.handleOnClick)} />;
};API
callback
Type: Function
Default: undefined
Required: true
Function you want to execute when enter or space event was passed in.
License
MIT © Daniel Husar
1.0.0
7 years ago