Skip to content

Interface: Menu ​

Controller returned by createMenu().

Properties ​

PropertyModifierTypeDescription
itemsreadonlyreadonly MenuItem[]The items passed in options.

Methods ​

close() ​

ts
close(options?): void;

Close and move focus to the trigger (default), the editor, or nowhere.

Parameters ​

ParameterType
options?{ focus?: "editor" | "trigger" | "none"; }
options.focus?"editor" | "trigger" | "none"

Returns ​

void


getItemProps() ​

ts
getItemProps(id): ElementProps;

Props for an item: role menuitemradio with aria-checked for choices, menuitem for actions; aria-disabled when it cannot run. Click selects it. Throws for an unknown id.

Parameters ​

ParameterType
idstring

Returns ​

ElementProps


getMenuProps() ​

ts
getMenuProps(): ElementProps;

Props for the menu: role="menu", aria-labelledby. Arrow keys, Home and End move focus, letters jump by label, Enter and Space choose, Escape closes to the trigger, Tab closes.

Returns ​

ElementProps


getState() ​

ts
getState(): MenuState;

The current state; the same object until something changes.

Returns ​

MenuState


getTriggerProps() ​

ts
getTriggerProps(): ElementProps;

Props for the menu button: id, aria-label (menu label plus the checked item), aria-haspopup, aria-expanded, aria-controls. Click toggles; ArrowDown, Enter and Space open the menu, ArrowUp opens it on the last item.

Returns ​

ElementProps


openMenu() ​

ts
openMenu(focus?): void;

Open and focus an enabled item: the checked one (default; else the first), the first or the last.

Parameters ​

ParameterType
focus?"selected" | "first" | "last"

Returns ​

void


select() ​

ts
select(id): void;

Close, focus the editor and run the item's command. Ignored for a disabled or unknown item.

Parameters ​

ParameterType
idstring

Returns ​

void


subscribe() ​

ts
subscribe(listener): () => void;

Call listener on every state change; returns the unsubscribe function.

Parameters ​

ParameterType
listener() => void

Returns ​

() => void