Menu
The WAI-ARIA menu button pattern: arrows move, Home and End jump, typing a letter jumps, Enter chooses and Escape gives focus back to the button. ArrowUp opens at the last item. Check items stay open; actions close first, so anything they open remembers the button. One pill springs between items whether focus moves by keyboard or pointer.
- role=menu
- Roving focus
- Typeahead
- Spring Physics
- Popover API
- Brand guidelines.pdfPinned
- Launch plan.md
- Interview notes.md
Tab to a ⋯ button and press ArrowDown, then use the arrows, Home and End, or type a letter. Escape gives focus back to the button. Pin to top stays open; everything else closes.
Usage
Drop it in
import { Menu } from "@/app/lib/components/menu";<Menu
trigger={<IconButton aria-label="Project actions"><MoreHorizontal size={16} /></IconButton>}
items={[
{ label: "Rename", shortcut: "R", onSelect: rename },
{ type: "separator" },
{ label: "Delete", tone: "danger", onSelect: remove },
]}
/>API
Props
| Prop | Type | Default |
|---|---|---|
trigger*The button that opens it. It gets aria-haspopup, aria-expanded and aria-controls. | ReactElement | — |
items* | MenuItem[] | — |
sidePreferred side. It flips when there is no room. Default: "bottom" | Side | "bottom" |
alignAlignment along the trigger. Default: "start" | Align | "start" |
offsetGap from the trigger in px. Default: 6 | number | 6 |
positioning"auto" uses CSS anchor positioning where the browser has it, "js" always measures. Default: "auto" | Positioning | "auto" |
onOpenChangeCalled whenever it opens or closes. | (open: boolean) => void | — |
className | string | "" |
Read from the component's source at build time. * required.
Accessibility
Works with
- Cursor
- Reacts to where the pointer is, not just whether it's over the element.
- Touch
- Follows your finger while it's down, then settles a moment after you lift.
- Keyboard
- Focus lights it up the way the cursor does. Every action has a key.
- Reduced motion
- Nothing moves or springs. Colour still answers, without drifting.