Build a reusable dropdown menu (an "actions" menu button) that follows the WAI-ARIA Menu Button pattern.
The starter renders an Actions button and a static list of items that's always visible.
export function MenuButton({ label, items }) // items: [{ id, label, onSelect, disabled? }]
The demo App uses the items Edit, Duplicate, Archive (disabled) and Delete, and shows Last action: <label> after a selection.
Mouse
onSelect, closes the menu and returns focus to the button. Clicking a disabled item does nothing.Keyboard (focus moves into the menu; items aren't in the Tab order)
ARIA
aria-haspopup="menu", aria-expanded and aria-controls. The menu has role="menu" and is labelled by the button. Items have role="menuitem", and disabled ones have aria-disabled="true".role="menu" versus a plain list of links in a disclosure?Spotted a mistake or a rights concern? Report an issue