Choose actions and settings from a button or a context menu.
Start with a trigger and a few actions. Add groups, checkboxes, radio choices, or submenus as the task grows. The menu handles focus, arrow keys, typeahead, and dismissal.
import { Component } from "@angular/core"
import { useLog } from "./log"
import {
Menu,
MenuContent,
MenuGroup,
MenuGroupLabel,
MenuItem,
MenuSeparator,
MenuTrigger,
} from "@ui-sdk/angular/menu"
@Component({
imports: [
Menu,
MenuContent,
MenuGroup,
MenuGroupLabel,
MenuItem,
MenuSeparator,
MenuTrigger,
],
template: `
<ng-container uiMenu (action)="log('Chose ' + $event.value)">
<button uiMenuTrigger>Open Menu</button>
<div *uiMenuContent>
<div uiMenuGroup>
<div uiMenuGroupLabel>Project</div>
<div uiMenuItem value="overview">Overview</div>
<div uiMenuItem value="members">Members</div>
<div uiMenuItem value="settings">Settings</div>
</div>
<div uiMenuSeparator></div>
<div uiMenuGroup>
<div uiMenuGroupLabel>Help</div>
<div uiMenuItem value="docs">Documentation</div>
<div uiMenuItem value="feedback">Send feedback</div>
</div>
</div>
</ng-container>
`,
})
class Example {
readonly log = useLog()
}
export { Example }Installation
npm install @ui-sdk/angular @ui-sdk/coreComposition
Use the following composition to build Menu:
uiMenu
├── uiMenuTrigger
└── uiMenuContent
├── uiMenuItem
└── uiMenuItemGive items a value and handle (action) on the menu to run the selected command. A Group and GroupLabel can organize related actions; a Separator divides them without becoming a focus stop.
Pass a promise to $event.waitUntil() in (action) or an item’s (select) to keep the item pending. It gets data-pending, aria-busy and aria-disabled, the menu stays open, and choosing it again does nothing until the promise settles. The menu closes once it resolves. A rejection keeps it open and puts the reason in the item’s error state until the next try. After a second, screen readers hear pendingAnnouncement, “Loading” by default.
Usage
Import the parts and put them together:
import { Component } from "@angular/core"
import { Menu, MenuContent, MenuItem, MenuTrigger } from "@ui-sdk/angular/menu"
@Component({
selector: "app-example",
imports: [Menu, MenuContent, MenuItem, MenuTrigger],
template: `
<ng-container uiMenu>
<button uiMenuTrigger>Actions</button>
<div *uiMenuContent>
<div uiMenuItem value="rename">Rename</div>
<div uiMenuItem value="duplicate">Duplicate</div>
</div>
</ng-container>
`,
})
class Example {}
export { Example }Submenus
Nest a Sub, SubTrigger, and SubContent to add another level. Hover or press the arrow key toward a submenu to open it. The menu lets a pointer travel diagonally into the submenu without accidentally choosing an item it passes over. Escape closes only the submenu and returns focus to its trigger, as the menu pattern asks.
import { Component } from "@angular/core"
import { LucideChevronRight } from "@lucide/angular"
import { useLog } from "./log"
import {
Menu,
MenuContent,
MenuItem,
MenuSeparator,
MenuSub,
MenuSubContent,
MenuSubTrigger,
MenuTrigger,
} from "@ui-sdk/angular/menu"
@Component({
imports: [
Menu,
MenuContent,
MenuItem,
MenuSeparator,
MenuSub,
MenuSubContent,
MenuSubTrigger,
MenuTrigger,
LucideChevronRight,
],
template: `
<ng-container uiMenu (action)="log('Chose ' + $event.value)">
<button uiMenuTrigger>Edit</button>
<div *uiMenuContent>
<div uiMenuItem value="undo" shortcut="mod+z">Undo</div>
<div uiMenuItem value="redo" shortcut="mod+shift+z">Redo</div>
<div uiMenuSeparator></div>
<ng-container uiMenuSub>
<div uiMenuSubTrigger>
Find
<svg lucideChevronRight></svg>
</div>
<div *uiMenuSubContent>
<div uiMenuItem value="find" shortcut="mod+f">Find…</div>
<div uiMenuItem value="find-next" shortcut="mod+g">Find next</div>
<div uiMenuItem value="find-previous" shortcut="mod+shift+g">
Find previous
</div>
</div>
</ng-container>
<ng-container uiMenuSub>
<div uiMenuSubTrigger>
Transform
<svg lucideChevronRight></svg>
</div>
<div *uiMenuSubContent>
<ng-container uiMenuSub>
<div uiMenuSubTrigger>
Case
<svg lucideChevronRight></svg>
</div>
<div *uiMenuSubContent>
<div uiMenuItem value="uppercase">Uppercase</div>
<div uiMenuItem value="lowercase">Lowercase</div>
</div>
</ng-container>
<div uiMenuItem value="trim">Trim whitespace</div>
</div>
</ng-container>
</div>
</ng-container>
`,
})
class Example {
readonly log = useLog()
}
export { Example }Shortcuts
An item’s shortcut displays a platform-specific hint and sets aria-keyshortcuts. mod+s reads as Command+S on Apple platforms and Control+S elsewhere.
In markup, this is a hint: your app owns the key handler. Data menus also register their shortcuts while closed. Letters and digits match physical keys, including combinations such as Option+N.
import { Component } from "@angular/core"
import { useLog } from "./log"
import {
Menu,
MenuContent,
MenuItem,
MenuSeparator,
MenuTrigger,
} from "@ui-sdk/angular/menu"
@Component({
imports: [Menu, MenuContent, MenuItem, MenuSeparator, MenuTrigger],
template: `
<ng-container uiMenu (action)="log('Chose ' + $event.value)">
<button uiMenuTrigger>File</button>
<div *uiMenuContent>
<div uiMenuItem value="new-tab" shortcut="mod+t">New tab</div>
<div uiMenuItem value="new-window" shortcut="mod+n">New window</div>
<div uiMenuItem value="open" shortcut="mod+o">Open…</div>
<div uiMenuSeparator></div>
<div uiMenuItem value="save" shortcut="mod+s">Save</div>
<div uiMenuItem value="save-as" shortcut="mod+shift+s">Save as…</div>
<div uiMenuSeparator></div>
<div uiMenuItem value="print" shortcut="mod+p">Print…</div>
</div>
</ng-container>
`,
})
class Example {
readonly log = useLog()
}
export { Example }Icons
Put decorative icons in ItemIcon so screen readers and typeahead ignore them. mirror flips a directional icon in right-to-left text. An icon-only item still needs an aria-label.
data-has-icon on items and data-has-icons on the menu let text line up when only some items have icons.
import { Component } from "@angular/core"
import {
LucideCode,
LucideDownload,
LucideLink,
LucideMail,
LucideReply,
LucideShare,
} from "@lucide/angular"
import { useLog } from "./log"
import {
Menu,
MenuContent,
MenuItem,
MenuItemIcon,
MenuSeparator,
MenuTrigger,
} from "@ui-sdk/angular/menu"
@Component({
imports: [
Menu,
MenuContent,
MenuItem,
MenuItemIcon,
MenuSeparator,
MenuTrigger,
LucideCode,
LucideDownload,
LucideLink,
LucideMail,
LucideReply,
LucideShare,
],
template: `
<ng-container uiMenu (action)="log('Chose ' + $event.value)">
<button uiMenuTrigger>
<svg lucideShare></svg>
Share
</button>
<div *uiMenuContent>
<div uiMenuItem value="copy-link">
<span uiMenuItemIcon>
<svg lucideLink></svg>
</span>
Copy link
</div>
<div uiMenuItem value="email">
<span uiMenuItemIcon>
<svg lucideMail></svg>
</span>
Email
</div>
<div uiMenuItem value="reply">
<span uiMenuItemIcon mirror>
<svg lucideReply></svg>
</span>
Reply
</div>
<div uiMenuSeparator></div>
<div uiMenuItem value="download">
<span uiMenuItemIcon>
<svg lucideDownload></svg>
</span>
Download
</div>
<div uiMenuItem value="embed">
<span uiMenuItemIcon>
<svg lucideCode></svg>
</span>
Embed
</div>
</div>
</ng-container>
`,
})
class Example {
readonly log = useLog()
}
export { Example }Checkboxes
Checkbox items toggle independently and stay open by default. Use [(checked)], or defaultChecked for an uncontrolled item. *uiMenuItemIndicator renders the check; keepMounted preserves its space while unchecked. Style data-checked and data-unchecked for each state.
import { Component } from "@angular/core"
import { LucideCheck } from "@lucide/angular"
import { useLog } from "./log"
import {
Menu,
MenuCheckboxItem,
MenuContent,
MenuGroup,
MenuGroupLabel,
MenuItemIndicator,
MenuSeparator,
MenuTrigger,
} from "@ui-sdk/angular/menu"
@Component({
imports: [
Menu,
MenuCheckboxItem,
MenuContent,
MenuGroup,
MenuGroupLabel,
MenuItemIndicator,
MenuSeparator,
MenuTrigger,
LucideCheck,
],
template: `
<ng-container
uiMenu
(checkedChange)="
log($event.value + ' ' + ($event.checked ? 'on' : 'off'))
"
>
<button uiMenuTrigger>View</button>
<div *uiMenuContent>
<div uiMenuGroup>
<div uiMenuGroupLabel>Appearance</div>
<div uiMenuCheckboxItem value="status-bar" defaultChecked>
<span uiMenuItemIndicator keepMounted>
<svg lucideCheck></svg>
</span>
Status bar
</div>
<div uiMenuCheckboxItem value="minimap">
<span uiMenuItemIndicator keepMounted>
<svg lucideCheck></svg>
</span>
Minimap
</div>
</div>
<div uiMenuSeparator></div>
<div uiMenuCheckboxItem value="line-numbers" defaultChecked>
<span uiMenuItemIndicator keepMounted>
<svg lucideCheck></svg>
</span>
Line numbers
</div>
<div uiMenuCheckboxItem value="word-wrap">
<span uiMenuItemIndicator keepMounted>
<svg lucideCheck></svg>
</span>
Word wrap
</div>
</div>
</ng-container>
`,
})
class Example {
readonly log = useLog()
}
export { Example }Radio Group
Radio items choose one value in their group and stay open by default. Use [(value)], or defaultValue for an uncontrolled group. Give the group a name when it should identify itself in the menu’s (valueChange) output.
import { Component } from "@angular/core"
import { useLog } from "./log"
import {
Menu,
MenuContent,
MenuGroupLabel,
MenuItemIndicator,
MenuRadioGroup,
MenuRadioItem,
MenuSeparator,
MenuTrigger,
} from "@ui-sdk/angular/menu"
@Component({
imports: [
Menu,
MenuContent,
MenuGroupLabel,
MenuItemIndicator,
MenuRadioGroup,
MenuRadioItem,
MenuSeparator,
MenuTrigger,
],
template: `
<ng-container uiMenu>
<button uiMenuTrigger>Panel</button>
<div *uiMenuContent>
<div
uiMenuRadioGroup
name="position"
defaultValue="bottom"
(beforeValueChange)="log('Panel at the ' + $event.value)"
>
<div uiMenuGroupLabel>Position</div>
@for (option of ["Top", "Bottom", "Right"]; track option) {
<div uiMenuRadioItem [value]="option.toLowerCase()">
<span *uiMenuItemIndicator></span>
{{ option }}
</div>
}
</div>
<div uiMenuSeparator></div>
<div
uiMenuRadioGroup
defaultValue="comfortable"
(beforeValueChange)="log($event.value + ' density')"
>
<div uiMenuGroupLabel>Density</div>
@for (option of ["Compact", "Comfortable"]; track option) {
<div uiMenuRadioItem [value]="option.toLowerCase()">
<span *uiMenuItemIndicator></span>
{{ option }}
</div>
}
</div>
</div>
</ng-container>
`,
})
class Example {
readonly log = useLog()
}
export { Example }Context Menu
A ContextTrigger opens at a right-click or long press. Give the area a tab stop so Shift+F10 and the context-menu key can open it from the keyboard. Right-clicking elsewhere in the same area repositions an open menu.
Set disabled to leave that area’s native browser menu available. Context triggers can pass a payload too.
import { Component } from "@angular/core"
import { useLog } from "./log"
import {
Menu,
MenuContent,
MenuContextTrigger,
MenuItem,
MenuSeparator,
} from "@ui-sdk/angular/menu"
@Component({
imports: [Menu, MenuContent, MenuContextTrigger, MenuItem, MenuSeparator],
template: `
<ng-container uiMenu (action)="log('Chose ' + $event.value)">
<div uiMenuContextTrigger [tabindex]="0">
Right-click or long-press here
</div>
<div *uiMenuContent>
<div uiMenuItem value="back">Back</div>
<div uiMenuItem value="forward" disabled>Forward</div>
<div uiMenuItem value="reload">Reload</div>
<div uiMenuSeparator></div>
<div uiMenuItem value="save">Save page as…</div>
<div uiMenuItem value="print">Print…</div>
</div>
</ng-container>
`,
})
class Example {
readonly log = useLog()
}
export { Example }Placement
side and align choose the starting position. The menu flips or shifts when it does not fit; data-side reports where it ended up. Logical alignment and submenu keys follow the surrounding text direction. See the shared popup guide for the positioning contract.
<div *uiMenuContent="{ side: 'right', align: 'start' }"></div>Offsets and Collision Padding
sideOffset sets the gap, alignOffset shifts along the anchor, and collisionPadding leaves room around the viewport. Use --anchor-width to match the trigger's width and --available-height to scroll a long list.
<div
*uiMenuContent="{ sideOffset: 8, alignOffset: -4, collisionPadding: 24 }"
></div>Modal
The default modal="pointer" consumes an outside press while closing the menu. true also locks scrolling and makes the page inert. false lets the outside press reach its target after closing.
<ng-container uiMenu [modal]="false">
<button uiMenuTrigger>Actions</button>
<div *uiMenuContent></div>
</ng-container>Submenu Delay
delay is the hover wait in milliseconds, 100 by default. It applies to the submenus directly inside that menu. Set it on a Sub to change the delay for the next level.
<ng-container uiMenu [delay]="300">
<button uiMenuTrigger>File</button>
<div *uiMenuContent>
<ng-container uiMenuSub [delay]="0">
<div uiMenuSubTrigger>Open recent</div>
<div *uiMenuSubContent></div>
</ng-container>
</div>
</ng-container>Keyboard Navigation
Arrow keys wrap by default; loop false stops at the ends. Typing finds an item by name. If an item has extra descriptive text, set label to the text typeahead should match. label does not replace its accessible name; use aria-label for that.
<ng-container uiMenu [loop]="false">
<button uiMenuTrigger>Status</button>
<div *uiMenuContent>
<div uiMenuItem value="busy" label="Do not disturb">
Do not disturb
<span>Notifications are muted</span>
</div>
</div>
</ng-container>A menu holds items, groups and separators. For a text field beside a list of choices, like a search box or a rename field, use a Popover. The field keeps its keys there, while in a menu the pointer moves focus from item to item.
Focus After Closing
When the menu closes with focus inside it, focus returns to the trigger. If an action removes the trigger or moves people on to something else, set finalFocus on the content to a selector, an element or a function returning one, or to "none" to leave focus where the action put it. See popup focus for the shared focus rules.
<div *uiMenuContent="{ finalFocus: '#file-list' }"></div>Disabled Items
Disabled items remain focusable so people can discover them, but cannot run or open a submenu. A disabled Trigger is a native disabled button and cannot receive focus. Add focusableWhenDisabled to keep it in the tab order, so it can host a tooltip that says why; presses still do nothing.
import { Component } from "@angular/core"
import { LucideCheck, LucideChevronRight } from "@lucide/angular"
import { useLog } from "./log"
import {
Menu,
MenuCheckboxItem,
MenuContent,
MenuGroupLabel,
MenuItem,
MenuItemIndicator,
MenuRadioGroup,
MenuRadioItem,
MenuSeparator,
MenuSub,
MenuSubContent,
MenuSubTrigger,
MenuTrigger,
} from "@ui-sdk/angular/menu"
@Component({
imports: [
Menu,
MenuCheckboxItem,
MenuContent,
MenuGroupLabel,
MenuItem,
MenuItemIndicator,
MenuRadioGroup,
MenuRadioItem,
MenuSeparator,
MenuSub,
MenuSubContent,
MenuSubTrigger,
MenuTrigger,
LucideCheck,
LucideChevronRight,
],
template: `
<div data-slot="row">
<ng-container uiMenu (action)="log('Chose ' + $event.value)">
<button uiMenuTrigger>Document</button>
<div *uiMenuContent>
<div uiMenuItem value="undo" shortcut="mod+z" disabled>Undo</div>
<div uiMenuItem value="redo" shortcut="mod+shift+z">Redo</div>
<div uiMenuSeparator></div>
<div uiMenuCheckboxItem value="autosave" defaultChecked disabled>
<span *uiMenuItemIndicator>
<svg lucideCheck></svg>
</span>
Autosave
</div>
<div uiMenuSeparator></div>
<div uiMenuRadioGroup defaultValue="pdf">
<div uiMenuGroupLabel>Export as</div>
<div uiMenuRadioItem value="pdf">
<span *uiMenuItemIndicator>
<svg lucideCheck></svg>
</span>
PDF
</div>
<div uiMenuRadioItem value="docx" disabled>
<span *uiMenuItemIndicator>
<svg lucideCheck></svg>
</span>
Word
</div>
<div uiMenuRadioItem value="markdown">
<span *uiMenuItemIndicator>
<svg lucideCheck></svg>
</span>
Markdown
</div>
</div>
<div uiMenuSeparator></div>
<ng-container uiMenuSub>
<div uiMenuSubTrigger disabled>
Move to
<svg lucideChevronRight></svg>
</div>
<div *uiMenuSubContent>
<div uiMenuItem>Archive</div>
</div>
</ng-container>
</div>
</ng-container>
<ng-container uiMenu>
<button uiMenuTrigger disabled>Locked</button>
<div *uiMenuContent>
<div uiMenuItem>Unlock</div>
</div>
</ng-container>
</div>
`,
})
class Example {
readonly log = useLog()
}
export { Example }Keeping the Menu Open
Plain items close when selected; checkbox and radio items stay open. closeOnSelect changes either default. A selection handler can also prevent the default event to keep it open for one action.
<div uiMenuItem [closeOnSelect]="false" (select)="zoom += 10">Zoom in</div>
<div uiMenuCheckboxItem value="fit" closeOnSelect>Fit to window</div>Container
Menus render in place and use the top layer. container moves the popup to another element; submenus remain inside their parent popup. Pass the actual element after it exists, as the popup guide explains.
<div *uiMenuContent="{ container: panel }"></div>Animation
The menu stays mounted through an exit animation. data-starting-style, data-ending-style, data-side, and --transform-origin describe the transition. keepMounted leaves the closed content hidden afterward; (openChangeComplete) reports when it finishes.
import { Component } from "@angular/core"
import { LucideChevronRight } from "@lucide/angular"
import { useLog } from "./log"
import {
Menu,
MenuContent,
MenuItem,
MenuSeparator,
MenuSub,
MenuSubContent,
MenuSubTrigger,
MenuTrigger,
} from "@ui-sdk/angular/menu"
@Component({
imports: [
Menu,
MenuContent,
MenuItem,
MenuSeparator,
MenuSub,
MenuSubContent,
MenuSubTrigger,
MenuTrigger,
LucideChevronRight,
],
template: `
<ng-container
uiMenu
(beforeOpenChange)="log($event.value ? 'Opening' : 'Closing')"
(openChangeComplete)="
log($event ? 'Finished opening' : 'Finished closing')
"
>
<button uiMenuTrigger>Animated</button>
<div *uiMenuContent="{ keepMounted: true }">
<div uiMenuItem>Back</div>
<div uiMenuItem>Forward</div>
<div uiMenuItem>Reload</div>
<div uiMenuSeparator></div>
<ng-container uiMenuSub>
<div uiMenuSubTrigger>
More tools
<svg lucideChevronRight></svg>
</div>
<div *uiMenuSubContent>
<div uiMenuItem>Save page as…</div>
<div uiMenuItem>Developer tools</div>
</div>
</ng-container>
</div>
</ng-container>
`,
})
class Example {
readonly log = useLog()
}
export { Example }Presentation
presentation="auto" uses a sheet on small touch screens and a popover elsewhere; "sheet" always requests a sheet. The sheet keeps menu roles and keys. Submenus replace the current level, and Escape or the arrow toward the parent goes back. Context menus and menus in a menubar remain popovers.
Use data-presentation or the content’s presentation state for the two layouts. Leave a sheet’s translation to the SDK. --sheet-backdrop sets its dimming color, and the sheet is modal unless modal is false. The popup guide covers shared presentation behavior.
import { Component } from "@angular/core"
import {
LucideChevronRight,
LucideDownload,
LucideLink,
LucideShare,
LucideTrash,
} from "@lucide/angular"
import { useLog } from "./log"
import {
Menu,
MenuContent,
MenuItem,
MenuSeparator,
MenuSub,
MenuSubContent,
MenuSubTrigger,
MenuTrigger,
} from "@ui-sdk/angular/menu"
@Component({
imports: [
Menu,
MenuContent,
MenuItem,
MenuSeparator,
MenuSub,
MenuSubContent,
MenuSubTrigger,
MenuTrigger,
LucideChevronRight,
LucideDownload,
LucideLink,
LucideShare,
LucideTrash,
],
template: `
<ng-container
uiMenu
presentation="sheet"
(action)="log('Chose ' + $event.value)"
>
<button uiMenuTrigger>Options</button>
<div *uiMenuContent>
<div uiMenuItem value="share">
<svg lucideShare></svg>
Share
</div>
<div uiMenuItem value="copy-link">
<svg lucideLink></svg>
Copy link
</div>
<ng-container uiMenuSub>
<div uiMenuSubTrigger>
<svg lucideDownload></svg>
Move to
<svg lucideChevronRight></svg>
</div>
<div *uiMenuSubContent>
<div uiMenuItem value="inbox">Inbox</div>
<div uiMenuItem value="archive">Archive</div>
</div>
</ng-container>
<div uiMenuSeparator></div>
<div uiMenuItem value="delete" destructive>
<svg lucideTrash></svg>
Delete
</div>
</div>
</ng-container>
`,
})
class Example {
readonly log = useLog()
}
export { Example }Controlled
Use [(open)], or pass open and update it in (beforeOpenChange). A change carries a reason, and $event.cancel() can refuse it. A controller can open the menu from another control; see state and events and controllers for that shared pattern.
import { Component, signal } from "@angular/core"
import { Menu, MenuContent, MenuTrigger } from "@ui-sdk/angular/menu"
@Component({
selector: "app-example",
imports: [Menu, MenuContent, MenuTrigger],
template: `
<ng-container uiMenu [(open)]="open">
<button uiMenuTrigger>Actions</button>
<div *uiMenuContent></div>
</ng-container>
`,
})
class Example {
readonly open = signal(false)
}
export { Example }Triggers Outside the Menu
Connect external triggers and one menu to a createMenuController<File>(). Each trigger passes its row as payload, which the content reads from its state. Only the active trigger is expanded and receives focus back. Code can also open with a payload and anchor; the Promise resolves when the menu closes.
import { Component } from "@angular/core"
import { LucideEllipsis } from "@lucide/angular"
import { useLog } from "./log"
import {
createMenuController,
Menu,
MenuContent,
type MenuContentState,
MenuGroup,
MenuGroupLabel,
MenuItem,
MenuSeparator,
MenuTrigger,
} from "@ui-sdk/angular/menu"
type File = { name: string; size: string }
@Component({
imports: [
Menu,
MenuContent,
MenuGroup,
MenuGroupLabel,
MenuItem,
MenuSeparator,
MenuTrigger,
LucideEllipsis,
],
template: `
<div data-slot="stack">
<div data-slot="controls">
<button (click)="openFirst($event)">
Open {{ files[0].name }} Actions
</button>
</div>
<ul data-slot="list">
@for (file of files; track file.name) {
<li data-slot="row">
{{ file.name }}
<span data-slot="hint">{{ file.size }}</span>
<button
uiMenuTrigger
[controller]="menu"
[payload]="file"
[attr.aria-label]="\`Actions for \${file.name}\`"
data-variant="ghost"
data-size="sm"
>
<svg lucideEllipsis></svg>
</button>
</li>
}
</ul>
<ng-container
uiMenu
[controller]="menu"
(action)="log($event.value + ' ' + menu.getPayload()?.name)"
>
<div *uiMenuContent="{ align: 'end' }; let content">
<div uiMenuGroup>
<div uiMenuGroupLabel>{{ payloadOf(content)?.name }}</div>
<div uiMenuItem value="open">Open</div>
<div uiMenuItem value="rename">Rename</div>
<div uiMenuItem value="duplicate">Duplicate</div>
</div>
<div uiMenuSeparator></div>
<div uiMenuItem value="delete">Delete</div>
</div>
</ng-container>
</div>
`,
})
class Example {
readonly files: File[] = [
{ name: "Roadmap.pdf", size: "2.4 MB" },
{ name: "Budget.xlsx", size: "860 KB" },
{ name: "Team photo.jpg", size: "5.1 MB" },
]
readonly menu = createMenuController<File>()
readonly log = useLog()
async openFirst(event: MouseEvent) {
const result = await this.menu.open({
payload: this.files[0],
anchor: event.currentTarget as HTMLElement,
})
this.log(`Closed with ${result.reason}`)
}
payloadOf(state: { payload?: unknown }) {
return state.payload as File | undefined
}
}
export { Example }Menus as Data
items accepts MenuData: actions, groups, checkboxes, radio groups, and submenus. A string is shorthand for an item whose label and value match. Put uiMenuItems inside the content to render them as bare parts. Data menus register their shortcuts even while closed; set itemShortcuts to false to turn that off.
The menu's (checkedChange) emits the checkbox's value and whether it's checked; its (valueChange) emits the radio group's name in group and its new value. Either change can be canceled with $event.cancel(). You can also render your own parts from the same data while items keeps the shortcuts registered. The lists and menus guide covers the data shape.
import { Component } from "@angular/core"
import {
Menu,
MenuContent,
type MenuData,
MenuItems,
MenuTrigger,
} from "@ui-sdk/angular/menu"
@Component({
selector: "app-example",
imports: [Menu, MenuContent, MenuItems, MenuTrigger],
template: `
<ng-container uiMenu [items]="fileMenu" (action)="run($event.value)">
<button uiMenuTrigger>File</button>
<div *uiMenuContent>
<div uiMenuItems></div>
</div>
</ng-container>
`,
})
class Example {
readonly fileMenu: MenuData = [
{ value: "open", label: "Open…", shortcut: "mod+o" },
{ type: "separator" },
{
type: "checkbox",
value: "toolbar",
label: "Toolbar",
defaultChecked: true,
},
{
type: "radio-group",
name: "sort",
label: "Sort by",
defaultValue: "name",
items: [
{ value: "name", label: "Name" },
{ value: "date", label: "Date modified" },
],
},
{ type: "submenu", label: "Share", items: ["Copy link", "Email"] },
]
run(command: string) {
console.log(command)
}
}
export { Example }Links and Custom Rendering
Render an item as a native link using the shared composition API. Enter follows the link like a click, preserving its target and modifier-key behavior.
<a uiMenuItem href="#composition">Composition</a>Custom Rendering
See Links and Custom Rendering for a native link. The shared composition guide covers element replacement and state-based rendering.
Styling
Use data-highlighted for the active item, data-disabled for unavailable actions, and data-checked for selected settings. Popup sizing and motion hooks are shared with the styling guide.
Each part has a data-slot, such as menu-item, and its state attributes are listed under Data Attributes.
MenuContent
| Variable | What it holds |
|---|---|
--anchor-width | Width of the anchor, usually the trigger. Use it to match widths. |
--anchor-height | Height of the anchor. |
--available-width | Space beside the popup, up to the viewport edge. Not inherited either. |
--available-height | Space between the anchor and the viewport edge. Use it for max-height. Not inherited, so a child that needs it copies it on the popup, like [--list-height:var(--available-height)], and reads max-h-(--list-height). The first popup registers both names for the whole page with CSS.registerProperty, so they don't inherit anywhere. A page that needs them to inherit calls it first, with inherits: true. An @property rule can't, since a registration in script wins. |
--transform-origin | The point on the anchor the popup opens from. Use it to scale from the right place. |
--arrow-offset | Where the anchor's center falls along the popup's edge, kept arrowPadding from the corners. Position a ::before arrow with it. |
--drawer-progress | While it presents as a sheet: how far open the sheet is, from 0 closed to 1 at its largest snap point. Never past 1. |
--drawer-dim | While it presents as a sheet: how dim the page behind is, from 0 to 1. The backdrop's opacity follows it. |
--drawer-expand | While it presents as a sheet: 0 at the second-largest snap point and below, 1 at the largest. With one snap point, the whole travel. |
--drawer-stack | While it presents as a sheet: how many sheets opened from inside this one are open above it, rising smoothly as each one opens. Push it back with it. |
--sheet-backdrop | Set it yourself: the color the page dims to while it presents as a sheet. Black at 0.2 by default. |
Viewport
| Variable | What it holds |
|---|---|
--keyboard-inset | While it presents as a sheet: how many pixels of the page the on-screen keyboard covers, 0 without one. |
--visual-viewport-width | While it presents as a sheet: the width of the part of the page you can see. |
--visual-viewport-height | While it presents as a sheet: the height of the part of the page you can see, above the keyboard. |
--visual-viewport-top | While it presents as a sheet: how far the part of the page you can see is scrolled from the top of the layout, as when the keyboard pushes it up. |
Data Attributes
uiMenuRadioGroup, uiMenuGroup, uiMenuGroupLabel, uiMenuSeparator and uiMenuShortcut have no state attributes.
MenuTrigger
[data-slot="menu-trigger"]
| Attribute | What it means |
|---|---|
data-closed | Present on a trigger while the menu isn't open from it. |
data-open | Present on the trigger that opened the menu, while it's open. |
MenuContextTrigger
[data-slot="menu-context-trigger"]
| Attribute | What it means |
|---|---|
data-closed | Present on an area while the menu isn't open from it. |
data-disabled | Present when the area is disabled. |
data-open | Present on the area that opened the menu, while it's open. |
MenuContent
[data-slot="menu-content"]
| Attribute | What it means |
|---|---|
data-closed | Present while the menu is closed, including while it animates out. |
data-presentation | popoversheetHow the menu presents this time it's open. Submenus present like their root. |
data-nested | Present on submenus. |
data-open | Present while the menu is open. A submenu trigger has it while its submenu is open. |
data-starting-style | Present for the first frame. Style the state you animate from. |
data-ending-style | Present while the menu animates out. Style the state you animate to. |
data-side | toprightbottomleftWhere the menu ended up, after flipping away from edges. |
data-align | startcenterendHow the menu lines up with its trigger. |
data-has-icons | Present while any item inside holds an icon part, so items without one can line up. |
MenuItem
[data-slot="menu-item"]
| Attribute | What it means |
|---|---|
data-disabled | Present when the item can't be chosen. |
data-highlighted | Present on the item with keyboard focus or under the pointer. |
data-has-icon | Present on an item while it holds an icon part. |
MenuCheckboxItem
[data-slot="menu-checkbox-item"]
| Attribute | What it means |
|---|---|
data-checked | Present on checked checkbox items, and on the radio item that's its group's value. |
data-unchecked | Present on items that aren't checked. |
data-highlighted | Present on the item with keyboard focus or under the pointer. |
MenuItemIndicator
[data-slot="menu-item-indicator"]
| Attribute | What it means |
|---|---|
data-checked | Present while its item is checked. |
data-unchecked | Present while its item isn't checked, with keepMounted. |
MenuRadioItem
[data-slot="menu-radio-item"]
| Attribute | What it means |
|---|---|
data-checked | Present on checked checkbox items, and on the radio item that's its group's value. |
data-unchecked | Present on items that aren't checked. |
data-highlighted | Present on the item with keyboard focus or under the pointer. |
MenuItemIcon
[data-slot="menu-item-icon"]
| Attribute | What it means |
|---|---|
data-mirror | Present on an icon that flips in right-to-left text, with mirror. |
API Reference
Each option below is an input on the directive, and each callback an output. A change callback is two outputs: (beforeOpenChange), with the details and cancel(), then (openChange) with the new value alone. open, checked and value can be bound with [(open)], [(checked)] and [(value)].
Menu
container?DocumentFragment | Element | null- Renders the popup into this element instead of in place, like a container inside a shadow root or an iframe. On web components, a CSS selector. Nested popups stay inside their parent.
open?boolean- Whether the menu is open. Pass it to control the menu.
defaultOpen?boolean- Whether the menu starts open, when uncontrolled.
(beforeOpenChange)- Runs when the menu wants to open or close.
details.reasonsays why, anddetails.cancel()stops it. (openChangeComplete)- Runs once the menu has finished opening or closing, after any animation.
(beforePayloadChange)- Runs when the payload the content shows changes: a trigger or context area with another payload opens the menu, or takes the open menu over, which fires no
(beforeOpenChange), and so does a controller'sopen({ payload })on the open menu.details.cancel()keeps the previous payload. (action)- Runs for every plain item, including items in submenus, with the item's value. Return a Promise to mark the item pending until it settles: it gets
data-pending,aria-busyandaria-disabled, the menu stays open, and choosing it again waits. It closes once the Promise resolves, and a rejection keeps it open with the reason in the item'serrorstate until the next try. pendingAnnouncement?string- What screen readers hear once an item has been pending for a second, so a slow action doesn't pass in silence. Set it in the page's language. An empty string says nothing.
(beforeCheckedChange)- Runs when any checkbox item in the menu or its submenus toggles, with the item's value in
details.value. Made for data menus. (beforeValueChange)- Runs when any radio group in the menu or its submenus changes, with the group in
details.group. Made for data menus. items?MenuData- The menu as data. Renders the content for you, unless you place a content part of your own, and runs the items' shortcuts.
itemShortcuts?boolean- Whether a data menu runs its items' shortcuts while closed.
loop?boolean- Whether arrow keys wrap from the last item to the first.
delay?number- Milliseconds the pointer rests on a submenu trigger before its submenu opens.
presentation?PresentationSetting<"popover">- How the menu presents.
"sheet"slides it up from the bottom of the screen, where it can be swiped away and submenus open in its place, and"auto"does that on small touch screens. Decided each time it opens; the server renders"popover"for"auto". A context menu and a menu in a menubar are always popovers. controller?MenuController- Opens, closes and inspects the menu from anywhere, and connects triggers outside it. Create one with
createMenuController(). modal?"pointer" | boolean"pointer": an outside press only closes the menu.true: also locks scroll, traps focus and makes the rest of the page inert.false: outside presses reach what they hit.dismissible?boolean- Whether Escape, an outside press, focus or the window leaving, Android's back gesture and a sheet's swipe can close it. Triggers, Close parts and the controller always can. Pass
falsewhile it holds unsaved work, and ask in(dismissAttempt). (dismissAttempt)- Runs when
dismissiblerefused a dismissal made on purpose: Escape, an outside press, back or a swipe. Focus or the window leaving is refused without it. Ask "Discard changes?" here. debug?boolean- Logs every state change with its reason to the console, in development builds.
MenuTrigger
A trigger outside the menu also takes controller.
disabled?boolean- Stops the trigger from opening the menu. A native button can't be focused or pressed, unless
focusableWhenDisabledis set. focusableWhenDisabled?boolean- Keeps a disabled trigger in the tab order with
aria-disabledinstead of the native attribute, so it can host a tooltip that says why. Presses still do nothing. payload?unknown- Data for the content to render when this trigger opens the menu, like the row it belongs to.
shortcut?string- A keyboard shortcut that opens the menu from anywhere, like
"mod+j".modis Command on Apple platforms and Control elsewhere. Setsaria-keyshortcuts. controller?PopupController<any, MenuOpenChangeReason, MenuOpenOptions, string, MenuPayloadChangeReason>- Connects a trigger outside the menu, like one per table row, to the menu with this controller.
MenuContextTrigger
disabled?boolean- Stops a right-click, a long press or Shift+F10 from opening the menu here. The browser's own menu shows instead.
payload?unknown- Data for the content to render when this area opens the menu, like the row it belongs to.
controller?PopupController<any, MenuOpenChangeReason, MenuOpenOptions, string, MenuPayloadChangeReason>- Connects an area outside the menu to the menu with this controller.
MenuContent
side?Side- Which side of the anchor the popup opens on. Flips to the other side when there isn't room. Which side of the trigger the menu opens on. Submenus open to the side, mirrored in right-to-left layouts.
align?Align- How the popup lines up with the anchor along that side.
startandendfollow the reading direction. How the menu lines up with the trigger along that side. sideOffset?number- Gap between the anchor and the popup, in pixels. Gap between the trigger and the menu, in pixels.
alignOffset?number- Shift along the anchor, in pixels. Shift along the trigger, in pixels. Submenus default to lining up their first item with the trigger.
collisionPadding?number- Space to keep from the viewport edges, in pixels.
arrowPadding?number- Space to keep between the arrow and the popup's corners, in pixels.
anchor?string | Anchor | null- Positions the popup against this instead of its trigger: an element, a CSS selector, a point like
{ x, y }, or anything withgetBoundingClientRect(). It's read on every check, so it can move. A controller'sopen({ anchor })wins for that open. container?DocumentFragment | Element | null- Renders the popup into this element instead of in place, like a container inside a shadow root or an iframe. On web components, a CSS selector. Nested popups stay inside their parent.
finalFocus?PopupFocusTarget- Where focus goes when the menu closes while focus is inside it.
"trigger"returns it to the trigger and"none"leaves it. A CSS selector, an element or a function picks a specific element. keepMounted?boolean- Whether the menu stays in the page, hidden, while closed. Its content keeps its state between opens.
MenuItem
value?string- Passed to
(action)when the item runs. label?string- The text typeahead matches, when the content isn't plain text. It isn't the accessible name: use
aria-labelfor that. disabled?boolean- Keeps the item focusable but stops it from running, as the menu pattern asks. Sets
data-disabledandaria-disabled. destructive?boolean- Styles the item as dangerous, like Delete. Sets
data-destructive. shortcut?string- A keyboard shortcut like
"mod+n". Shows⌘Non Apple platforms andCtrl+Nelsewhere, and setsaria-keyshortcuts. closeOnSelect?boolean- Whether running the item closes the menu.
(select)- Runs when the item is selected, by pointer or keyboard, with the event that selected it, or a new
selectEvent when no DOM event did. Callevent.preventDefault()to keep the menu open and skip(action). Return a Promise to mark the item pending until it settles, like(action).
MenuCheckboxItem
valuestring- Identifies the item, in the menu's
(beforeCheckedChange). label?string- The text typeahead matches, when the content isn't plain text. It isn't the accessible name: use
aria-labelfor that. disabled?boolean- Keeps the item focusable but stops it from toggling, as the menu pattern asks.
checked?boolean- Whether the item is checked. Pass it to control the item.
defaultChecked?boolean- Whether the item starts checked, when uncontrolled.
(beforeCheckedChange)- Runs when the item wants to toggle.
details.reasonsays why, anddetails.cancel()stops it. closeOnSelect?boolean- Whether toggling closes the menu.
MenuRadioGroup
value?T | null- The selected value. Pass it to control the group.
nullselects nothing. defaultValue?T | null- The value selected at first, when uncontrolled.
(beforeValueChange)- Runs when the selection wants to change.
details.reasonsays why, anddetails.cancel()stops it. name?string- Identifies the group in the menu's
(beforeValueChange). Defaults to a generated id, and the group then keeps its choice by its place among the menu's groups. Give a group that's shown only some of the time a name, so it keeps its own.
MenuRadioItem
valuestring- Selected in the group when the item is chosen.
label?string- The text typeahead matches, when the content isn't plain text. It isn't the accessible name: use
aria-labelfor that. disabled?boolean- Keeps the item focusable but stops it from being chosen, as the menu pattern asks.
closeOnSelect?boolean- Whether choosing the item closes the menu.
MenuItemIndicator
keepMounted?boolean- Whether the indicator stays in the page while its item is unchecked, so it can be styled or animated in both states.
MenuItemIcon
mirror?boolean- Flips the icon horizontally in right-to-left text, for icons that point a way, like arrows and chevrons. Icons that picture a thing, like a clock or a check, stay as they are.
MenuSub
debug?boolean- Logs every state change with its reason to the console, in development builds.
open?boolean- Whether the submenu is open. Bind it with
[(open)]to control the submenu. defaultOpen?boolean- Whether the submenu starts open, when uncontrolled.
(beforeOpenChange)- Runs when the menu wants to open or close.
details.reasonsays why, anddetails.cancel()stops it. (openChangeComplete)- Runs once the menu has finished opening or closing, after any animation.
loop?boolean- Whether arrow keys wrap from the last item to the first.
delay?number- Milliseconds the pointer rests on a submenu trigger before its submenu opens.
controller?MenuController- Opens, closes and inspects the submenu. Create one with
createMenuController(). Triggers outside the menu can't connect to it.
MenuSubTrigger
disabled?boolean- Keeps the submenu trigger focusable but stops it from opening its submenu, as the menu pattern asks. Sets
data-disabledandaria-disabled.
MenuSubContent
It takes the same inputs as uiMenuContent.
MenuGroup, MenuGroupLabel and MenuSeparator
These take no inputs of their own.
State
What each part's state() signal holds, per part.
uiMenuTrigger, uiMenuContextTrigger and uiMenuSubTrigger:
openboolean- Whether the menu is open from this trigger.
disabledboolean- Whether the trigger's
disabledprop is set, or the menubar it's in is disabled.
uiMenuContent:
openboolean- Whether the menu is open. False while it animates out.
nestedboolean- Whether this is a submenu.
presentationPresentation- How the menu is shown.
payloadPayload | undefined- The payload of the last open, from the trigger that opened it or a controller, typed as the controller's
Payload.
uiMenuItem:
highlightedboolean- Whether the item has keyboard focus or is under the pointer.
disabledboolean- Whether the item can't be chosen.
pendingboolean- Whether its
onSelectoronActionPromise is running. errorunknown- Why its last action failed, until it runs again.
uiMenuCheckboxItem and uiMenuRadioItem:
highlightedboolean- Whether the item has keyboard focus or is under the pointer.
disabledboolean- Whether the item can't be chosen.
checkedboolean- Whether the item is on: its
checkedprop when you pass one, otherwisedefaultCheckeduntil a press changes it.
uiMenuRadioGroup:
valuestring | null- The selected value, or null when nothing is selected.
uiMenuItemIndicator:
checkedboolean- Whether its checkbox item is on, or its radio item is its group's value. While false, the indicator isn't shown unless
keepMountedis set. disabledboolean- Whether the item can't be chosen.
uiMenuItemIcon:
mirrorboolean- Whether it flips in right-to-left text.
Reasons
$event.reason says why the menu or a submenu opened or closed.
trigger-pressMouseEvent | KeyboardEvent | TouchEvent- Click, tap, Enter or Space on the part that opens, closes or toggles. Arrow keys that open a menu or submenu count too. A tap on a combobox's input that opens a sheet reports its
touchend. trigger-hoverPointerEvent- The pointer rested on a trigger, or left it, with hover opening.
item-pressMouseEvent | KeyboardEvent- A member of a collection was chosen: a menu item, a tab, a radio or a checkbox item.
outside-pressMouseEvent- A press outside the layer.
escape-keyKeyboardEvent- Escape, or a submenu's close key (ArrowLeft in left-to-right layouts).
close-pressMouseEvent | KeyboardEvent | SubmitEvent- A Close part was pressed, or a form with
method="dialog"was submitted. focus-outKeyboardEvent | FocusEvent- Focus left the layer, or Tab moved it out.
window-blurFocusEvent- The window lost focus.
submenu-switchKeyboardEvent | PointerEvent- Another submenu in the same menu, or another menu in the same menubar, took over.
parent-closenone- The parent layer closed.
trigger-releasePointerEvent- A press-and-hold open was released outside the popup.
backEvent- Going back: the Android back button or gesture, or Backspace in an empty command input, which returns to the previous page.
shortcutKeyboardEvent- A keyboard shortcut, like a trigger's
shortcut. swipeTouchEvent | PointerEvent- A swipe gesture: a finger, mouse or pen dragged it.
anchor-hiddennone- The element the popup sits beside stopped rendering, like a trigger a breakpoint hides.
imperativenone- A controller or
apicall.
For a payload change, it says what opened the menu or took it over.
trigger-pressMouseEvent | KeyboardEvent | TouchEvent- Click, tap, Enter or Space on the part that opens, closes or toggles. Arrow keys that open a menu or submenu count too. A tap on a combobox's input that opens a sheet reports its
touchend. trigger-hoverPointerEvent- The pointer rested on a trigger, or left it, with hover opening.
shortcutKeyboardEvent- A keyboard shortcut, like a trigger's
shortcut. imperativenone- A controller or
apicall.
With dismissible false, the refused dismissals (dismissAttempt) reports:
outside-pressMouseEvent- A press outside the layer.
escape-keyKeyboardEvent- Escape, or a submenu's close key (ArrowLeft in left-to-right layouts).
backEvent- Going back: the Android back button or gesture, or Backspace in an empty command input, which returns to the previous page.
swipeTouchEvent | PointerEvent- A swipe gesture: a finger, mouse or pen dragged it.
Checkbox items report why they toggled, in (beforeCheckedChange):
item-pressMouseEvent | KeyboardEvent- A member of a collection was chosen: a menu item, a tab, a radio or a checkbox item.
imperativenone- A controller or
apicall.
Radio groups report why their value changed, in (beforeValueChange):
item-pressMouseEvent | KeyboardEvent- A member of a collection was chosen: a menu item, a tab, a radio or a checkbox item.
imperativenone- A controller or
apicall.
Controller
Create one with createMenuController<Payload>() and pass it to [controller], on the menu and on any triggers outside it. Payload is the type of the data triggers and open() pass.
Every write method takes an optional { reason, event }, passed to (beforeOpenChange). open() also takes focus: "first", "last", "popup" or "none".
isOpen()() => boolean- Whether it's open. False as soon as it starts closing, while it still animates out.
setOpen(open, options?)(open: boolean, options?: PopupChangeOptions<MenuOpenChangeReason> | undefined) => boolean- Opens or closes it. Returns false when the change was canceled or it was already open or closed.
open(options?)(options?: (PopupChangeOptions<MenuPayloadChangeReason> & { payload?: Payload | undefined; anchor?: Anchor | undefined; signal?: AbortSignal | undefined; } & MenuOpenOptions) | undefined) => Promise<...>- Opens it, and resolves once it closes, with why, how and any return value. Resolves exactly once and never rejects: on the next close from any source, when
signalaborts, or with reason"unmount"when the component leaves the page. close(options?)(options?: (PopupChangeOptions<MenuOpenChangeReason> & { returnValue?: Result | undefined; }) | undefined) => boolean- Closes it.
returnValueis passed to the promiseopen()returned. Returns false when the close was canceled or it was already closed. toggle(options?)(options?: PopupChangeOptions<MenuOpenChangeReason> | undefined) => boolean- Opens it when it's closed, and closes it when it's open. Returns false when the change was canceled.
getPayload()() => Payload | undefined- The payload of the last open, from a controller or the trigger that opened it.
focus()() => void- Moves focus to the trigger that opened it last, or the first trigger.
Events
A before output emits { value, reason, event, cancel() } before the change, and its plain output follows with the value alone. A bound open, checked or value only updates when its change isn't canceled.
| Binding | On | Receives |
|---|---|---|
[(open)] | uiMenu | Whether the menu is open |
(beforeOpenChange) | uiMenu | { value, reason, cancel() }: the new state, and the reason |
(openChangeComplete) | uiMenu | $event, whether it's open, after the animation |
(beforePayloadChange) | uiMenu | { value, reason, cancel() }: the content's new payload, and the reason |
(action) | uiMenu | { value, event, waitUntil() } for every plain item, including items in submenus |
(checkedChange) | uiMenu | { value, checked, reason, cancel() } for any checkbox item. For data menus |
(valueChange) | uiMenu | { group, value, reason, cancel() } for any radio group. For data menus |
(dismissAttempt) | uiMenu | { reason, event }, when a dismissal was refused |
[(open)] | uiMenuSub | Whether the submenu is open |
(select) | uiMenuItem | { event, waitUntil() }, before the menu closes. $event.event.preventDefault() keeps it open |
[(checked)] | uiMenuCheckboxItem | Whether the item is checked. (beforeCheckedChange) has the details |
[(value)] | uiMenuRadioGroup | The selected value. (beforeValueChange) has the details |
Accessibility
The menu follows the WAI-ARIA menu button pattern.
Tested Behavior
Every line below is an automated test.
- Advertises its menu and reflects the open state.
- Click opens the menu and moves focus into it.
- Click on the open trigger closes the menu.
- Enter opens the menu and focuses the first item.
- Space opens the menu and focuses the first item.
- ArrowDown opens the menu and focuses the first item.
- ArrowUp opens the menu and focuses the last item.
- Open written back during openchange keeps focus on the last item. Web components only.
- Open written back after openchange keeps focus on the last item. Web components only.
- SetOpen(true) on an open menu leaves focus where it is. Web components only.
- A click on a trigger in a shadow root opens the menu, and it stays open. Vue and web components only.
- ArrowDown and ArrowUp move between items, skipping separators and labels.
- ArrowDown and ArrowUp skip items the page hides.
- Disabled items are focusable.
- Focus wraps at both ends.
- Home and End move to the first and last items.
- Typing a character moves to the next item that starts with it.
- Typing several characters quickly matches the whole prefix.
- Enter on an item runs it, closes the menu and returns focus.
- Clicking an item runs it and closes the menu.
- Disabled items do nothing.
- Checkbox items toggle and keep the menu open.
- Radio items select one value and keep the menu open.
- Hovering an item highlights it.
- Escape closes the menu and returns focus to the trigger.
- Clicking outside closes the menu.
- Escape while an input method is composing text leaves the menu open.
- Pressing a scrollbar outside the menu leaves it open.
- Tab closes the menu.
- The submenu trigger advertises its menu.
- ArrowRight opens the submenu and focuses its first item.
- Enter opens the submenu and focuses its first item.
- Space opens the submenu and focuses its first item.
- ArrowLeft closes the submenu and returns focus to its trigger.
- Nested submenus open and run their items.
- Submenu keyboard navigation stays inside the submenu.
- Keys pressed in quick succession are never lost.
- Clicking outside closes every menu.
Runs in React, Vue and web components.
Screen readers hear the same thing in each tested framework, recorded by a virtual screen reader:
- Announcements while using the menu with a keyboard.
- Item shortcuts are announced.
Runs in React, Vue and web components.