Menu Button
Connect a command trigger to a native popover menu. Custom element
<ui-menu-button> <button class="ui-button" data-ui-part="trigger" type="button">Actions</button> <ui-menu id="actions" role="menu" popover="auto" aria-label="Actions"> <button role="menuitem" type="button">Duplicate</button> <button role="menuitem" type="button">Archive</button> </ui-menu></ui-menu-button>Install
import '@timelessui/components/css/tokens.css'import '@timelessui/components/css/button.css'import '@timelessui/components/css/menu.css'import '@timelessui/components/css/popover.css'import '@timelessui/components/define/ui-menu-button'import '@timelessui/components/define/ui-menu'Anatomy
Parts are authored in your own markup and identified by the selector below, so your CSS can target the same anatomy without loading Timeless styles. Required parts must be present for the component to work. Private data-ui-internal-* hooks are written by the runtime and must never be authored.
<ui-menu-button>
| Part | Required | Selector | Purpose |
|---|---|---|---|
trigger | Yes | [data-ui-part~='trigger'] | Native button that opens the menu. |
content | Yes | [popover] | The popover surface holding a ui-menu. |
<ui-menu>
| Part | Required | Selector | Purpose |
|---|---|---|---|
menu | Yes | [role='menu'] | The menu container. Use role="menubar" for a persistent horizontal menu bar. |
item | Yes | [role^='menuitem'] | One command. Use role="menuitem", or menuitemcheckbox / menuitemradio with aria-checked. Timeless manages roving tabindex and typeahead. |
Attributes
Every value below is implemented by the stylesheets this component ships. Boolean attributes are presence-based: author the attribute with no value, or omit it.
<ui-menu-button>
| Attribute | Values | Default | Description |
|---|---|---|---|
open | presence | absent | Present to render the menu open on load. |
placement | bottom · top · right · left | bottom | Preferred side of the trigger. |
<ui-menu>
| Attribute | Values | Default | Description |
|---|---|---|---|
orientation | horizontal · vertical | vertical | Arrow-key axis. Defaults to horizontal when the menu part is role="menubar". |
Element API
Attributes above are the authoring surface. These are the DOM properties and events the registered element adds once it upgrades.
<ui-menu-button>
| Property | Type | Notes |
|---|---|---|
open | boolean | Reflects the open attribute, documented above. |
placement | 'bottom' | 'top' | 'right' | 'left' | Reflects the placement attribute, documented above. |
| Event | Detail | Description |
|---|---|---|
ui-open | CustomEvent<MenuButtonToggleDetail> | Dispatched after the menu opens. |
ui-close | CustomEvent<MenuButtonToggleDetail> | Dispatched after the menu closes. |
<ui-menu>
| Property | Type | Notes |
|---|---|---|
orientation | 'horizontal' | 'vertical' | Reflects the orientation attribute, documented above. |
This element dispatches no component events.
Styling
Root identity: ui-menu-button, ui-menu. Required stylesheets: tokens.css, button.css, menu.css, popover.css.
This component adds no custom properties of its own. Restyle it through the design tokens or your own CSS.
Design tokens this component reads (34)
These are global Atmosphere tokens. Change them once at the theme level rather than per component.
--ui-accent · --ui-accent-soft · --ui-bg-accent · --ui-bg-accent-active · --ui-bg-accent-hover · --ui-bg-control · --ui-bg-control-active · --ui-bg-control-hover · --ui-bg-control-muted · --ui-bg-danger · --ui-bg-danger-active · --ui-bg-danger-hover · --ui-bg-surface · --ui-bg-surface-raised · --ui-disabled-opacity · --ui-duration-fast · --ui-ease-standard · --ui-fg · --ui-fg-muted · --ui-focus · --ui-line · --ui-radius-control · --ui-radius-lg · --ui-radius-md · --ui-radius-sm · --ui-shadow-control-accent · --ui-shadow-control-active · --ui-shadow-control-danger · --ui-shadow-floating · --ui-shadow-outline-control · --ui-space-1 · --ui-space-2 · --ui-space-3 · --ui-space-4
Accessibility
Keep the native elements, roles, and relationships shown in the example. Timeless adds only the state and keyboard coordination the platform does not already provide, and it never supplies your accessible names — those depend on your content.
<ui-menu-button>
Follows the Menu Button pattern from the ARIA Authoring Practices Guide.
| Key | Action |
|---|---|
| Enter / Space / Arrow Down | Open the menu and focus its first item. |
| Escape | Close the menu and return focus to the trigger. |
Escape and outside-click dismissal come from the Popover API rather than from Timeless. The trigger carries aria-haspopup="menu" and aria-expanded.
<ui-menu>
Follows the Menu and Menubar pattern from the ARIA Authoring Practices Guide.
| Key | Action |
|---|---|
| Arrow keys | Move focus between items along the orientation axis. |
| Home / End | Move focus to the first or last enabled item. |
| Enter / Space | Activate the focused item. |
| Escape | Close the menu and return focus to whatever opened it. |
| Printable characters | Typeahead: jump to the next item whose label starts with what you typed. |
The menu is one tab stop and disabled items are skipped. Typeahead matching is locale-aware.
Before JavaScript runs
The markup above is complete and usable on its own: native controls submit, labels associate, and authored ARIA is already correct. Registration adds state synchronisation, focus management, and keyboard coordination on top of it.
More examples
Open Menu Button in StoryLite for variants, controls, and manual testing.