Overview
Menubar provides a horizontal menu bar with dropdown menus, similar to what you’d find in desktop applications. It supports submenus, keyboard navigation, and various item types including checkboxes and radio groups.Features
- Full keyboard navigation
- Supports submenus with customizable alignments
- Supports items, labels, groups of items
- Supports checkable items (single or multiple)
- Supports modal and non-modal modes
- Customize side, alignment, offsets, collision handling
- Focus automatically moved to first item when menu opens
- Typeahead support
- Dismissing and layering behavior highly customizable
Installation
Anatomy
API Reference
Root
Contains all the menu bar items.The controlled value of the menu to open.
The value of the menu that should be open initially.
Event handler called when the value changes.
The reading direction. If omitted, assumes LTR.
Whether keyboard navigation should loop from last item to first, and vice versa.
Menu
A top level menu item, contains a trigger with content combination.A unique value that associates the item with a content.
Trigger
The button that toggles the menu content. By default, the menu opens on click.Change the default rendered element for the one passed as a child.
Portal
When used, portals the content part into the body.Specify a container element to portal the content into.
Used to force mounting when more control is needed.
Content
The component that pops out when a menu is open.Whether keyboard navigation should loop from last item to first, and vice versa.
Event handler called when focus moves back after closing.
Event handler called when the escape key is down.
Event handler called when a pointer event occurs outside the bounds of the component.
Event handler called when focus moves outside the bounds of the component.
Event handler called when an interaction happens outside the bounds of the component.
Used to force mounting when more control is needed.
The preferred side of the trigger to render against.
The distance in pixels from the trigger.
The preferred alignment against the trigger.
An offset in pixels from the “start” or “end” alignment options.
When true, overrides the side and align preferences to prevent collisions with boundary edges.
The element(s) used as collision boundary.
The distance in pixels from the boundary edges where collision detection should occur.
The padding between the arrow and the edges of the content.
The sticky behavior on the align axis.
Whether to hide the content when the trigger becomes fully occluded.
Item
The component that contains the menu items.When true, prevents the user from interacting with the item.
Event handler called when the user selects an item.
Optional text used for typeahead purposes. By default the typeahead behavior will use the text content.
CheckboxItem
An item that can be controlled and rendered like a checkbox.The controlled checked state of the item.
Event handler called when the checked state changes.
When true, prevents the user from interacting with the item.
RadioGroup
Used to group multiple RadioItems.The controlled value of the radio item to check.
Event handler called when the value changes.
RadioItem
An item that can be controlled and rendered like a radio.The unique value of the item.
When true, prevents the user from interacting with the item.
ItemIndicator
Renders when the parent CheckboxItem or RadioItem is checked. You can style this element directly, or use it as a wrapper to put an icon into.Used to force mounting when more control is needed.
Separator
Used to visually separate items in the menu.Sub
Contains all the parts of a submenu.The open state of the submenu when it is initially rendered.
The controlled open state of the submenu.
Event handler called when the open state changes.
SubTrigger
An item that opens a submenu.When true, prevents the user from interacting with the item.
Optional text used for typeahead purposes.
SubContent
The component that pops out when a submenu is open.Accepts all the same props as Content.
Group
Used to group multiple items. Use in conjunction with Label to ensure good accessibility via automatic labelling.Label
Used to render a label. It won’t be focusable using arrow keys.Arrow
An optional arrow element to render alongside the content.The width of the arrow in pixels.
The height of the arrow in pixels.
Example
Accessibility
Adheres to the Menu Button WAI-ARIA design pattern and uses roving tabindex to manage focus movement among menu items.
Keyboard Interactions
- Space/Enter - Opens the menu and focuses the first item.
- ArrowDown - Opens the menu and focuses the first item.
- ArrowUp - Opens the menu and focuses the last item.
- ArrowRight/ArrowLeft - When focus is on a trigger, moves focus to the next or previous trigger.
- Esc - Closes the menu and moves focus to the trigger.