MenusReact
A menu bar with commands and options for your application, as in a desktop app.
Rendered by React 19.3.1
198Tests passing in React · 0 failing
8.0 KiBSize
Not measured yetMemory
Not measured yetSpeed
productdevbook and 13 upstream authors8 commits · last
Installation
npm i @hamur/reactNot on npm yet. The package goes out under the chosen name.
Anatomy
Import the component and assemble its parts:
<Menubar />Examples
The demo at the top is the one example this component has so far.
API reference
4 props across 1 parts, in React syntax. className, style, render are listed once, under Shared props.
MenubarMenubar
The container for menus.
| Prop | Type | Default |
|---|---|---|
loopFocusWhether to loop keyboard focus back to the first item | boolean | true |
modalWhether the menubar is modal. | boolean | true |
disabledWhether the whole menubar is disabled. | boolean | false |
orientationThe orientation of the menubar. | MenuRootOrientation | 'horizontal' |
| Data attribute | Description |
|---|---|
data-modal | Present when the corresponding menubar is modal. |
data-orientation | Determines the orientation of the menubar. |
data-has-submenu-open | Present when any submenu within the menubar is open. |
Shared props
Every part that renders an element takes these.
| Prop | Type |
|---|---|
classNameCSS class applied to the element, or a function that
returns a class based on the component's state. | string | ((state: State) => string | undefined) |
styleStyle applied to the element, or a function that
returns a style object based on the component's state. | React.CSSProperties | ((state: State) => React.CSSProperties | undefined) |
renderAllows you to replace the component's HTML element
with a different tag, or compose it with another component. | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, State> |
Keyboard and accessibility
Keyboard
| Keys | Does | Part |
|---|---|---|
| ArrowLeftArrowRight | Moves between the menus' triggers | Menubar |
| HomeEnd | Moves to the first or last trigger | Menubar |
| Space | Opens the focused menu | Menubar |
| ArrowDownArrowUp | Moves through the open menu's items | Menubar |
| ArrowLeftArrowRight | With a menu open, opens the previous or next menu instead | Menubar |
| ArrowRight | Opens a submenu | Menubar |
| ArrowLeft | Closes a submenu and returns focus to its trigger | Menubar |
| Escape | Closes the open menu | Menubar |
Accessibility
| Part | Sets | So that |
|---|---|---|
| Menubar | role="menubar", aria-orientation | a screen reader announces a menu bar and which arrow keys move in it |
| Menubar | gives each Menu trigger inside role="menuitem" | the triggers are read as the bar's items |
Focus order
- The menubar is one tab stop: the last focused trigger, or the first.
- Arrow keys move between triggers; with a menu open, they move into and across menus.
Escapecloses the menu and leaves focus on its trigger.