Components › Components
Menu
A list of actions behind a button. The list is a popover, so opening, closing, Escape and a click outside come from the browser; the menu adds the keyboard.
Styled: Menu on ui.clarusjs.com, ready to copy, in plain CSS or Tailwind.
Picked: nothing yet
tscl
@import uiMenu from '@clarusjs/ui-primitives/menu.tscl'
@import uiMenuTrigger from '@clarusjs/ui-primitives/menu-trigger.tscl'
@import uiMenuList from '@clarusjs/ui-primitives/menu-list.tscl'
@import uiMenuItem from '@clarusjs/ui-primitives/menu-item.tscl'
<uiMenu id="file" (select)="run($event)">
<uiMenuTrigger>File</uiMenuTrigger>
<uiMenuList>
<uiMenuItem value="new">New</uiMenuItem>
<uiMenuItem value="open" [disabled]="true">Open…</uiMenuItem>
</uiMenuList>
</uiMenu>idnames the menu: its trigger and list get ids from it, and the list is labelled by the trigger.(select)comes with the chosen item'svalue, then the menu closes;$info.cancel()keeps it open.- Keyboard: opening moves focus to the first item; ↑ ↓ move, Home and End jump, typing a letter goes to the item starting with it, Enter or Space picks, Escape closes and focus goes back to the trigger. Disabled items are skipped.
menu-trigger,menu-listandmenu-itemhave no script and ship nothing; the trigger and list read the menu's id from context. Only the menu itself is a small island.- Styling:
data-partmenu,trigger,menu-listandmenu-item;:popover-openon the list,aria-expandedon the trigger,aria-disabledon items.
From @clarusjs/ui-primitives, styled by @clarusjs/ui: @import '@clarusjs/ui/ui.css' once, and change the look with its --ui- tokens (--ui-accent, --ui-radius, --ui-font…). Without it, the part is unstyled and works the same.