Skip to content

MenuItem

MenuItem is a single row inside a Menu. Renders a four-zone layout: icon | text | shortcut | chevron. Hovering opens an attached submenu after a 150 ms delay (persistent-mode menus only).

You usually pass MenuItemConfig objects to MenuBar or Menu.show(...) instead of constructing MenuItems directly.

Config shape

MenuItemConfig:

FieldPurpose
textDisplay label.
actionCalled on click or Enter. Ignored when submenu is set.
enabledDefaults to true. Disabled items are dimmed and non-interactive.
shortcutHint string displayed on the right.
iconGlyph displayed on the left.
submenuNested MenuConfig; opens a submenu instead of firing action (persistent-mode only).
separatorWhen true, render as a horizontal rule and ignore other fields.

Layout

[ icon ] [ text ······························ ] [ shortcut ] [ ▶ ]

The chevron only appears for items with a submenu.

Theming

MenuItem reads its colours from one of two CSS-variable families chosen via the optional cssVarPrefix constructor argument ('menu-bar' or 'context-menu'). Menu selects the right family for its mode automatically — you only specify it when constructing items by hand.

Notes

  • The shortcut text is purely visual; it does not register a keyboard handler. Wire the binding yourself.
  • Use setFocused(true) to apply the keyboard focus style programmatically; this is what Menu does during arrow-key navigation.

See also