React MenuButton
react-menu-button is a React component for inclusive-menu-button meant to ease the use of accessible menu buttons in React applications.
Install
npm install --save react-menu-button
Usage
There are 3 required properties for the menu-button component:
id
: theid
attribute used internally by inclusive-menu-button to connect the button element and its menu.label
: the text content for the button element.children
: children to be rendered as the content of the menu (they should render<button>
elements).
Examples
Play with examples in the storybook playground.
const MenuButton = const DifficultyMenu = props <MenuButton ='difficulty' ='Difficulty' > <button ='button'>Easy</button> <button ='button'>Medium</button> <button ='button'>Hard</button> </MenuButton> ReactDOM
More complex example using the inclusive-menu-button instance to programmatically use its API.
const MenuButton = Component { thissaveMenuRef = thissaveMenuRef thisstate = choice: null } { thismenu = ref } { thismenu } { let label = 'Difficulty' if thisstatechoice label += ' ' + thisstatechoice return <MenuButton ='difficulty' = = > <button ='button'>Easy</button> <button ='button'>Medium</button> <button ='button'>Hard</button> </MenuButton> }
Inclusive-menu-button constructor options
In version 0.1.1, inclusive-menu-button introduced an optional object as second argument for its constructor to define settings for the menu instance. This object can be passed as an options
prop.
<MenuButton … => …</MenuButton>
Styling and class names
You can pass class names to the different parts of the menu button with props:
className
for the wrapperbuttonClassName
for the buttonmenuClassName
for the menu