Menu
Commands, links, checkboxes and submenus in a popover anchored to a trigger.
c2-menu
Attributes
| Name | Type | Default | Description |
|---|---|---|---|
open | boolean | false | Whether the menu is showing. Set it to open or close the menu from code. |
placement | Placement | bottom-start | Preferred placement of the surface (floating-ui names). Submenus default to `right-start`. |
anchor | string | HTMLElement | undefined | undefined | Anchor element, or (attribute) the id of an element in the same tree. Defaults to the slotted trigger. |
fit-anchor | boolean | false | Make the surface exactly as wide as the anchor instead of as wide as its content. |
keep-open | boolean | false | Keep the menu open after a row is activated. Also available per row as `keep-open`. |
disabled | boolean | false | Ignores the trigger and never opens. |
aria-label | string | null | null | Accessible name of the surface. |
Events
| Name | Type | Description |
|---|---|---|
menu-select | CustomEvent<MenuSelectEventDetail> | Bubbles from the activated row: `detail.value`, `detail.checked` and `detail.data` of that row. |
toggle | ToggleEvent | Fired after the menu opens or closes; `newState` is `open` or `closed`. |
CSS custom properties
Grouped by the element and state they target. Click a group to collapse it; click a name to copy it.
| Name | Type | Default | Description |
|---|---|---|---|
--c2-menu--background | color | #ffffff | |
--c2-menu--min-width | pixel | 128px | Floor for the surface, which is otherwise as wide as its content (and never narrower than a slotted trigger). |
--c2-menu--max-height | pixel | 320px | The menu scrolls past this height. |
--c2-menu--border-top | border | 1px solid #e4e4e7 | |
--c2-menu--border-right | border | 1px solid #e4e4e7 | |
--c2-menu--border-bottom | border | 1px solid #e4e4e7 | |
--c2-menu--border-left | border | 1px solid #e4e4e7 | |
--c2-menu--border-top-left-radius | border-radius | 8px | |
--c2-menu--border-top-right-radius | border-radius | 8px | |
--c2-menu--border-bottom-left-radius | border-radius | 8px | |
--c2-menu--border-bottom-right-radius | border-radius | 8px | |
--c2-menu--box-shadow | box-shadow | 0 8px 24px rgba(24, 24, 27, 0.08) | |
--c2-menu--padding-top | padding | 4px | |
--c2-menu--padding-right | padding | 4px | |
--c2-menu--padding-bottom | padding | 4px | |
--c2-menu--padding-left | padding | 4px | |
--c2-menu--gap | pixel | — | Space between the rows. |
--c2-menu__separator--color | color | #e4e4e7 | |
--c2-menu__separator--margin | margin | 4px 0 | |
--c2-menu__heading--color | color | #71717a | |
--c2-menu__heading--font-size | font-size | 11px | |
--c2-menu__heading--font-weight | font-weight | 600 | |
--c2-menu__heading--letter-spacing | letter-spacing | 0.06em | |
--c2-menu__heading--text-transform | text-transform | uppercase | |
--c2-menu__heading--padding-top | padding | 8px | |
--c2-menu__heading--padding-right | padding | 8px | |
--c2-menu__heading--padding-bottom | padding | 4px | |
--c2-menu__heading--padding-left | padding | 8px | |
c2-menu-item
Attributes
| Name | Type | Default | Description |
|---|---|---|---|
value | string | — | The value reported in `menu-select`. |
disabled | boolean | false | Dims the row and ignores clicks and keyboard. |
type | MenuItemType | item | `item` is a command, `checkbox` toggles, `radio` picks one row of a `name` group. |
checked | boolean | false | Checked state of a `checkbox` / `radio` row; shown as a check mark or a dot. |
name | string | undefined | — | Radio group name. Selecting a `radio` row unchecks the other rows of the same group in that menu. |
href | string | undefined | — | Makes the row a link; Enter and a click navigate, and `menu-select` still fires. |
target | string | undefined | — | |
destructive | boolean | false | Paints the row in the destructive colour, for delete-style commands. |
keep-open | boolean | false | Keeps the menu open after this row is activated, e.g. for a checkbox row. |
label | string | undefined | — | Label used for typeahead and as the default slot's fallback content. |
expanded | boolean | false | Set by the parent menu while this row's submenu is open. Announced as `aria-expanded`. |
reserve-indicator | boolean | false | Private: set by the parent menu on every row while any sibling is checkable, so the labels line up. |
Events
| Name | Type | Description |
|---|---|---|
menu-select | CustomEvent<MenuSelectEventDetail> | Fired after the row is activated by a click, Enter or Space. Cancelable; a row with a submenu never fires it. |
checked-change | CustomEvent<{ checked: boolean; value: string }> | Fired after the `checked` state of a `checkbox` / `radio` row changes. |
CSS custom properties
Grouped by the element and state they target. Click a group to collapse it; click a name to copy it.
| Name | Type | Default | Description |
|---|---|---|---|
--c2-menu-item--min-height | pixel | 32px | |
--c2-menu-item--gap | pixel | 8px | Space between the indicator, icons, label and shortcut. |
--c2-menu-item--border-top-left-radius | border-radius | 6px | |
--c2-menu-item--border-top-right-radius | border-radius | 6px | |
--c2-menu-item--border-bottom-left-radius | border-radius | 6px | |
--c2-menu-item--border-bottom-right-radius | border-radius | 6px | |
--c2-menu-item--padding-top | padding | 6px | |
--c2-menu-item--padding-right | padding | 8px | |
--c2-menu-item--padding-bottom | padding | 6px | |
--c2-menu-item--padding-left | padding | 8px | |
--c2-menu-item--font-size | font-size | 14px | |
--c2-menu-item--font-weight | font-weight | — | |
--c2-menu-item--font-style | font-style | — | |
--c2-menu-item--font-family | font-family | — | |
--c2-menu-item--line-height | pixel | 20px | |
--c2-menu-item--color | color | #18181b | |
--c2-menu-item--background | color | transparent | |
--c2-menu-item__hover--background | color | #f4f4f5 | Also the highlight of the keyboard-focused row. |
--c2-menu-item__hover--color | color | — | Defaults to the row colour. |
--c2-menu-item__description--color | color | #71717a | |
--c2-menu-item__description--font-size | font-size | 12px | |
--c2-menu-item__description--line-height | pixel | 16px | |
--c2-menu-item__description--margin-top | pixel | 1px | |
--c2-menu-item__shortcut--color | color | #a1a1aa | |
--c2-menu-item__shortcut--font-size | font-size | 12px | |
--c2-menu-item__shortcut--letter-spacing | letter-spacing | 0.04em | |
--c2-menu-item__icon--size | pixel | 16px | |
--c2-menu-item__icon--color | color | #71717a | |
--c2-menu-item__indicator--size | pixel | 16px | |
--c2-menu-item__indicator--color | color | — | The check mark / radio dot. Defaults to the row colour. |
--c2-menu-item__destructive--color | color | #dc2626 | Label and icon colour of a `destructive` row. |
--c2-menu-item__destructive__hover--background | color | #fef2f2 | |
--c2-menu-item__focus--outline | outline | 2px solid rgba(2, 101, 220, 0.4) | |
--c2-menu-item__focus--outline-offset | pixel | -2px | |
--c2-menu-item__disabled--opacity | opacity | 0.38 | |