0.1.12 • Published 4 years ago

use-menu-hook v0.1.12

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

useMenu

npm bundle size npm

The problem

You need an menu experience in your application and you want it to be accessible. You also want it to be simple and flexible to account for your use cases.

This solution

useMenu is a React hook that provides all the logic to create a WAI-ARIA menu component.

Installation

npm install use-menu-hook --save

// or
yarn add use-menu-hook

This packages depends on react, Please make sure you installed react as well.

Usage

Try it in the browser

import useMenu from "use-menu-hook";

function MenuButton() { const { getMenuButtonProps, getMenuItemProps, getMenuProps } = useMenu();

return (

<div className="App">
  <button {...getMenuButtonProps({ id: "colors" })}>Colors</button>
  <ul {...getMenuProps({ labelledBy: "colors" })}>
    <li {...getMenuItemProps({ id: "red" })}>Red</li>
    <li {...getMenuItemProps({ id: "green" })}>Green</li>
    <li {...getMenuItemProps({ id: "blue" })}>Blue</li>
  </ul>
</div>

); }

## More Examples

- [Menu button](https://codesandbox.io/s/github/nielswijers/use-menu-hook/tree/master/examples/menu-button)
- [With context](https://codesandbox.io/s/github/nielswijers/use-menu-hook/tree/master/examples/with-context)
- [With react-popper](https://codesandbox.io/s/github/nielswijers/use-menu-hook/tree/master/examples/with-react-popper)

## Inspiration
- [Navigation Menu Button Example](https://www.w3.org/TR/wai-aria-practices/examples/menu-button/menu-button-links.html)
- [Navigation Menubar Example](https://www.w3.org/TR/wai-aria-practices/examples/menubar/menubar-1/menubar-1.html)
- [useSelect](https://github.com/downshift-js/downshift/tree/master/src/hooks/useSelect)
0.1.11

4 years ago

0.1.12

4 years ago

0.1.10

4 years ago

0.1.8

4 years ago

0.1.9

4 years ago

0.1.7

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago