react-clickable-hocdeprecated

Executes onClick to keyboard actions for improved accessibility of your React components

Usage no npm install needed!

<script type="module">
  import reactClickableHoc from 'https://cdn.skypack.dev/react-clickable-hoc';
</script>

README

react-clickable-hoc

Build Status devDependencies Status

Executes onClick to keyboard actions for improved accessibility of your React components.

Pressing Enter or the space bar (onKeyDown) on the wrapped component will trigger onClick, if it exists.

Installation

Requires React v16.

npm install --save react-clickable-hoc

Usage

Simply import the module and wrap a component with it !

  import clickable from 'react-clickable-hoc';

  import Component from './path/to/Component';

  // Wrap the component using react-clickable-hoc.
  const WrappedComponent = clickable(Component);
  
  render() {
    const onClick = () => { console.log('clicked !') };
    // Use it like a normal component.
    return <WrappedComponent onClick={onClick} />
  }

License

MIT