Programmatic control
Open and close the menu from code, and change its content, theme, or animation at runtime.
What you'll see
Right-click or long-press the demo area to open the menu with “Option A” and “Option B”. The same menu could be opened from your own code with menu.open(x, y) or menu.open(button, { placement: "bottom-start" }). You can call menu.close(), menu.setMenu(...), menu.setOptions({ theme, position, animation }) to control state without user interaction.
Key points
- open(xOrEventOrElement?, yOrOptions?) — Show the menu. No args,
(x, y),(event), or(element, options?)withplacementandoffset. Returns a Promise with the selected item (or undefined). - close() — Close the menu; returns a Promise when the close animation finishes.
- getState() — Returns
{ isOpen, anchor, menu, rootElement }. - setMenu(menuOrUpdater) — Replace menu (array) or update with
(current) => newItems. - setOptions(options) — Change theme, position, animation, or lockScrollOutside at runtime.
Programmatic
Open from code: right-click here or use the button to open at element.
Or right-click hereOr long-press here
Related
- Basic usage — Opening and closing from code — open, close, getState.
- API reference — All instance methods and config options.
- Configuration — getAnchor, position, portal.