Menubar
Desktop-style File, Edit and View menus in one bar, with the arrow-key and hover movement of an application menu bar.
c2-menubar
A desktop-style menu bar: File, Edit, View… as a row of c2-menubar-menu children, each a trigger and the
c2-menu it opens. The bar is one Tab stop; the arrow keys move across it, and once a menu is open, hovering
another trigger or pressing ArrowLeft/ArrowRight inside the menu moves the open menu with it, the way an
application's menu bar does (WAI-ARIA menubar pattern).
Keyboard on a trigger: ArrowLeft/ArrowRight go to the previous/next menu (wrapping, mirrored right-to-left), Home/End to the first/last, a letter to the next menu whose label starts with it; Enter, Space or ArrowDown open the menu on its first row, ArrowUp on its last. Inside a menu, ArrowRight opens a submenu or, on a plain row, moves to the next menu; ArrowLeft closes a submenu or, at the top level, moves to the previous menu; Escape closes the menu and returns focus to its trigger.
The start and end slots hold what sits beside the menus (an app icon, a document title, a "Saved" status); they
are outside the menubar role. Activated rows fire menu-select, which bubbles from the row through the bar.
Attributes
| Name | Type | Default | Description |
|---|---|---|---|
aria-label | string | null | null | Accessible name of the menu bar ("Application", "Document"). |
Slots
| Name | Description |
|---|---|
default | The menus: c2-menubar-menu elements. |
start | Content before the menus, outside the menubar role (a logo or app icon). |
end | Content after the menus, outside the menubar role (a title, status or actions). |
Events
| Name | Type | Description |
|---|---|---|
menu-select | CustomEvent<MenuSelectEventDetail> | Bubbles from an activated row: detail.value, detail.checked and detail.data of that row. |
CSS parts
Shadow DOM styling hooks used with ::part(name). Prefer CSS custom properties when they cover the change.
| Name | Description |
|---|---|
menus | The element with the menubar role that holds the menus. |
CSS custom properties
Grouped by semantic target and state from --c2-<component>__<target>__<state>--<property>. Click a group to collapse it; click a name to copy it.
| Name | Type | Default | Description |
|---|---|---|---|
--c2-menubar--gap | pixel | 8px | Space between the start slot, the menus and the end slot. |
--c2-menubar--menus-gap | pixel | 2px | Space between two triggers. |
--c2-menubar--background-color | color | #ffffff | |
--c2-menubar--border | border | 1px solid #e4e4e7 | |
--c2-menubar--border-radius | border-radius | 8px | |
--c2-menubar--box-shadow | box-shadow | none | |
--c2-menubar--padding-top | padding | 4px | |
--c2-menubar--padding-right | padding | 4px | |
--c2-menubar--padding-bottom | padding | 4px | |
--c2-menubar--padding-left | padding | 4px | |
c2-menubar-menu
One menu of a c2-menubar: a trigger labelled label ("File", "Edit", …) and the rows it opens. The trigger is a
native button with the menuitem role, and the menu is a c2-menu anchored under it, so the rows are everything a
c2-menu takes: c2-menu-item children (checkbox and radio rows, shortcuts, descriptions, submenus), <hr>
separators and <h1>–<h6> group headings.
Keyboard and pointer movement across the bar belong to the c2-menubar around it; on its own the element behaves
like a menu button (Enter, Space or ArrowDown open on the first row, ArrowUp on the last, Escape closes).
Attributes
| Name | Type | Default | Description |
|---|---|---|---|
label | string | — | The trigger's text, which is also its accessible name. |
open | boolean | false | Whether the menu is showing. Set it to open or close the menu from code. |
disabled | boolean | false | Leaves the trigger focusable and announced but never opens the menu; the bar's arrow keys skip it. |
placement | Placement | bottom-start | Preferred placement of the menu (floating-ui names); it flips near the viewport edge. |
menu-label | string | — | Accessible name of the menu surface. Defaults to the trigger's name. |
Slots
| Name | Description |
|---|---|
default | The rows: c2-menu-item elements, <hr> separators and <h1>–<h6> group headings. |
Events
| Name | Type | Description |
|---|---|---|
menu-select | CustomEvent<MenuSelectEventDetail> | Bubbles from the activated row (from c2-menu-item, unchanged). |
toggle | ToggleEvent | The menu opened or closed; newState is open or closed. |
CSS parts
Shadow DOM styling hooks used with ::part(name). Prefer CSS custom properties when they cover the change.
| Name | Description |
|---|---|
trigger | The native button that opens the menu. |
CSS custom properties
Grouped by semantic target and state from --c2-<component>__<target>__<state>--<property>. Click a group to collapse it; click a name to copy it.
| Name | Type | Default | Description |
|---|---|---|---|
--c2-menubar-menu__trigger--height | pixel | 28px | |
--c2-menubar-menu__trigger--padding-left | padding | 10px | |
--c2-menubar-menu__trigger--padding-right | padding | 10px | |
--c2-menubar-menu__trigger--border-radius | border-radius | 6px | |
--c2-menubar-menu__trigger--font-size | font-size | 14px | |
--c2-menubar-menu__trigger--font-weight | font-weight | — | |
--c2-menubar-menu__trigger--font-family | font-family | — | |
--c2-menubar-menu__trigger--color | color | #18181b | |
--c2-menubar-menu__trigger--background-color | color | transparent | |
--c2-menubar-menu__trigger__hover--background-color | color | #f4f4f5 | |
--c2-menubar-menu__trigger__hover--color | color | — | |
--c2-menubar-menu__trigger__open--background-color | color | #f4f4f5 | |
--c2-menubar-menu__trigger__open--color | color | — | |
--c2-menubar-menu__trigger__open--font-weight | font-weight | — | |
--c2-menubar-menu__trigger__focus--outline | outline | 2px solid rgba(2, 101, 220, 0.4) | |
--c2-menubar-menu__trigger__focus--outline-offset | pixel | 0px | |
--c2-menubar-menu__trigger__disabled--opacity | number | 0.38 | |
--c2-menubar-menu__menu--offset | pixel | 4px | Gap between the trigger and its menu. |