Menu
A menu presents a list of actions or options from a trigger. Arrow keys move the highlight, typing a letter jumps to the matching item, Escape dismisses, and Enter selects. The panel is anchored to the trigger by the popover positioning engine, so opening one never shifts layout.
The component is composed from parts. <Menu> owns the state machine; the remaining parts read it from context, so they must all be rendered inside <Menu>.
Interactive Preview
Section titled “Interactive Preview”import { Menu, MenuTrigger, MenuPositioner, MenuContent, MenuItem, MenuSeparator, MenuItemGroup, MenuItemGroupLabel, MenuCheckboxItem, MenuRadioItem,} from "@/components/ui/menu";
export function UserMenu() { return ( <Menu onSelect={(d) => console.log(d.value)}> <MenuTrigger>Open menu</MenuTrigger> <MenuPositioner> <MenuContent> <MenuItem value="rename">Rename</MenuItem> <MenuSeparator /> <MenuItemGroup> <MenuItemGroupLabel>Notifications</MenuItemGroupLabel> <MenuCheckboxItem value="email">Email</MenuCheckboxItem> <MenuCheckboxItem value="sms">SMS</MenuCheckboxItem> </MenuItemGroup> <MenuSeparator /> <MenuItemGroup> <MenuItemGroupLabel>Frequency</MenuItemGroupLabel> <MenuRadioItem value="daily">Daily</MenuRadioItem> <MenuRadioItem value="weekly">Weekly</MenuRadioItem> </MenuItemGroup> </MenuContent> </MenuPositioner> </Menu> );}<script lang="ts"> import Menu from "@/components/ui/menu.svelte"; import MenuTrigger from "@/components/ui/menu-trigger.svelte"; import MenuPositioner from "@/components/ui/menu-positioner.svelte"; import MenuContent from "@/components/ui/menu-content.svelte"; import MenuItem from "@/components/ui/menu-item.svelte"; import MenuSeparator from "@/components/ui/menu-separator.svelte"; import MenuCheckboxItem from "@/components/ui/menu-checkbox-item.svelte"; import MenuRadioItem from "@/components/ui/menu-radio-item.svelte";</script>
<Menu> <MenuTrigger>Open menu</MenuTrigger> <MenuPositioner> <MenuContent> <MenuItem value="rename">Rename</MenuItem> <MenuSeparator /> <MenuCheckboxItem value="email">Email</MenuCheckboxItem> <MenuRadioItem value="daily">Daily</MenuRadioItem> </MenuContent> </MenuPositioner></Menu>import { Menu, MenuTrigger, MenuPositioner, MenuContent, MenuItem, MenuSeparator, MenuItemGroup, MenuItemGroupLabel, MenuCheckboxItem, MenuRadioItem,} from "@/components/ui/menu";
export function UserMenu() { return ( <Menu> <MenuTrigger>Open menu</MenuTrigger> <MenuPositioner> <MenuContent> <MenuItem value="rename">Rename</MenuItem> <MenuSeparator /> <MenuCheckboxItem value="email">Email</MenuCheckboxItem> <MenuRadioItem value="daily">Daily</MenuRadioItem> </MenuContent> </MenuPositioner> </Menu> );}Installation
Section titled “Installation”npx @glaceon/cli add menu --framework react # or svelte, solidData Attributes
Section titled “Data Attributes”| Attribute | Values | Applied to |
|---|---|---|
data-scope |
menu |
every part |
data-part |
trigger, positioner, content, item, separator, item-group, item-group-label, item-indicator, item-text |
matching part |
data-state |
open, closed |
trigger, content |
data-state |
checked, unchecked |
checkbox and radio items |
data-highlighted |
present / absent | items |
data-disabled |
present / absent | items |
Two behaviours are essential when styling this component:
- The content receives the
hiddenattribute while closed. Do not add an unconditional Tailwind display utility to it: a utility and the[hidden]rule have equal specificity, and the utility wins, which leaves a closed panel visible. - The positioner is never hidden. Zag hides the content inside it.
Option items carry role="menuitemcheckbox" / role="menuitemradio" with aria-checked, and their data-state reflects the checked state, so data-[state=checked] styling works on the item itself.
API Reference (Props)
Section titled “API Reference (Props)”| Part | Prop | Type | Description |
|---|---|---|---|
Menu |
children |
content | Trigger and panel |
Menu |
defaultOpen / open |
boolean |
Initial or controlled open state |
Menu |
onOpenChange |
(details) => void |
Called when the open state changes |
Menu |
onSelect |
(details) => void |
Called with the selected item value |
MenuTrigger |
children |
content | Trigger label |
MenuPositioner |
children |
content | Wraps the content; handles anchoring and the portal |
MenuContent |
children |
content | The panel |
MenuItem |
value |
string |
Required. Identifies the item to onSelect |
MenuItem |
disabled |
boolean |
Disables this item |
MenuSeparator |
None | None | A horizontal rule between items |
MenuItemGroup |
children |
content | Groups related items |
MenuItemGroupLabel |
children |
content | Label for the enclosing group |
MenuCheckboxItem |
value |
string |
Required. Toggles independently |
MenuRadioItem |
value |
string |
Required. One of a set |
Every part also accepts className (React) or class (Svelte, Solid), merged with cn().
Keyboard Interactions
Section titled “Keyboard Interactions”| Key | Behaviour |
|---|---|
Enter / Space |
Opens the menu, or activates the highlighted item |
Arrow Down / Arrow Up |
Moves the highlight, wrapping at the ends |
Home / End |
Jumps to the first or last item |
| Letter keys | Typeahead: jumps to the next item starting with that letter |
Escape |
Closes the menu and returns focus to the trigger |
Accessibility
Section titled “Accessibility”Items carry role="menuitem", and option items carry role="menuitemcheckbox" / role="menuitemradio" with aria-checked, all supplied by the Zag.js machine. The trigger is a real <button> exposing aria-expanded, aria-haspopup and aria-controls.
Rows are 44px tall (WCAG 2.2 SC 2.5.8) with a --surface-2 highlight, and focus rings use the --action token at 2px. The panel is z-50 over page content.