Menu
A menu of actions from a button: groups, checkbox and radio items, submenus, shortcuts. In the look of the app's style.
Usage
import { Component, ViewEncapsulation } from '@angular/core';import { ScButton, ScMenu, ScMenuContent, ScMenuGroup, ScMenuItem, ScMenuLabel, ScMenuPortal, ScMenuProvider, ScMenuSeparator, ScMenuTrigger,} from '@semantic-components/ui';
@Component({ selector: 'app-menu-usage-demo', imports: [ ScButton, ScMenu, ScMenuContent, ScMenuGroup, ScMenuItem, ScMenuLabel, ScMenuPortal, ScMenuProvider, ScMenuSeparator, ScMenuTrigger, ], template: ` <div scMenuProvider> <button scButton scMenuTrigger variant="outline">Open</button> <ng-template scMenuPortal> <div scMenu> <ng-template scMenuContent> <div scMenuGroup> <div scMenuLabel>My Account</div> <div scMenuItem value="Profile">Profile</div> <div scMenuItem value="Billing">Billing</div> <div scMenuItem value="Settings">Settings</div> </div> <div scMenuSeparator></div> <div scMenuItem value="Log out" variant="destructive">Log out</div> </ng-template> </div> </ng-template> </div> `, host: { class: 'flex w-full justify-center' }, encapsulation: ViewEncapsulation.None,})export class MenuUsageDemo {}Anatomy
Every part is a directive on your element; the text, the icons and the trigger's name are yours. The menu is in a template, rendered while it is open; its items in another, rendered once it has opened.
import { ScMenuProvider, ScMenuTrigger, ScMenuPortal, ScMenu, ScMenuContent, ScMenuGroup, ScMenuLabel, ScMenuItem, ScMenuCheckboxItem, ScMenuRadioGroup, ScMenuRadioItem, ScMenuItemIndicator, ScMenuSeparator, ScMenuSubmenuIcon,} from '@semantic-components/ui';<div scMenuProvider [(open)]="open"> <button scButton scMenuTrigger>…</button> <ng-template scMenuPortal> <div scMenu> <ng-template scMenuContent> <div scMenuGroup> <div scMenuLabel>…</div> <div scMenuItem value="…"> …<kbd scKbd>…</kbd> </div> </div> <div scMenuSeparator></div> <div scMenuCheckboxItem [(checked)]="…"> <span scMenuItemIndicator><svg></svg></span>… </div> <div scMenuRadioGroup [(value)]="…"> <div scMenuRadioItem value="…">…</div> </div> <div scMenuItem value="…">… <svg scMenuSubmenuIcon></svg> <ng-template scMenuPortal>…a submenu…</ng-template> </div> </ng-template> </div> </ng-template></div>Keyboard
- On the trigger, Enter, Space or ArrowDown opens the menu on its first item, ArrowUp on its last. A click opens it with nothing highlighted, until the pointer moves or a key is pressed.
- The arrows move, Home and End go to the ends, a letter goes to the item it starts.
- The arrow toward the reading end opens a submenu, the other way closes it (mirrored right to left).
- Enter or Space chooses an item; a checkbox or radio item toggles and the menu stays open.
- Escape closes the menu and gives focus back to the trigger; Tab closes it and moves on.
Examples
Basic
import { Component, ViewEncapsulation } from '@angular/core';import { ScButton, ScMenu, ScMenuContent, ScMenuGroup, ScMenuItem, ScMenuLabel, ScMenuPortal, ScMenuProvider,Submenu
import { Component, ViewEncapsulation } from '@angular/core';import { ScButton, ScKbd, ScMenu, ScMenuContent, ScMenuItem, ScMenuPortal, ScMenuProvider, ScMenuSeparator,Shortcuts
import { Component, ViewEncapsulation } from '@angular/core';import { ScButton, ScKbd, ScMenu, ScMenuContent, ScMenuGroup, ScMenuItem, ScMenuLabel, ScMenuPortal,Icons
import { Component, ViewEncapsulation } from '@angular/core';import { ScButton, ScMenu, ScMenuContent, ScMenuItem, ScMenuPortal, ScMenuProvider, ScMenuSeparator, ScMenuTrigger,Checkboxes
import { Component, ViewEncapsulation, signal } from '@angular/core';import { ScButton, ScMenu, ScMenuCheckboxItem, ScMenuContent, ScMenuGroup, ScMenuItemIndicator, ScMenuLabel, ScMenuPortal,Radio Group
import { Component, ViewEncapsulation, signal } from '@angular/core';import { ScButton, ScMenu, ScMenuContent, ScMenuGroup, ScMenuItemIndicator, ScMenuLabel, ScMenuPortal, ScMenuProvider,Destructive
import { Component, ViewEncapsulation } from '@angular/core';import { ScButton, ScMenu, ScMenuContent, ScMenuItem, ScMenuPortal, ScMenuProvider, ScMenuSeparator, ScMenuTrigger,Standalone
Chosen: nothing yet
import { Component, ViewEncapsulation, signal } from '@angular/core';import { ScFrame, ScMenu, ScMenuContent, ScMenuItem, ScMenuPortal, ScMenuSeparator, ScMenuSubmenuIcon,} from '@semantic-components/ui';RTL
import { Dir } from '@angular/cdk/bidi';import { Component, LOCALE_ID, ViewEncapsulation, signal } from '@angular/core';import { ScButton, ScKbd, ScMenu, ScMenuCheckboxItem, ScMenuContent, ScMenuGroup, ScMenuItem,API reference
Each part takes class, merged over the style (cn: a later class wins).
| Part | Selector | Description |
|---|---|---|
ScMenuProvider | div[scMenuProvider], span[scMenuProvider] | Holds the menu: [(open)]; side ('bottom' or 'top'), align, offset. Renders it in an overlay, with the trigger's direction and language. |
ScMenuTrigger | [scMenuTrigger] | Opens it; behaviour only, on any button (scButton for the look). Its name is yours. |
ScMenuPortal, ScMenuContent | ng-template[scMenuPortal], ng-template[scMenuContent] | The menu, rendered while it is open; its items, rendered once it has opened. A portal inside an item makes a submenu. |
ScMenu | div[scMenu] | The popup (role menu). Output itemSelected: the chosen item’s value. |
ScMenuItem | [scMenuItem] | An item: value, disabled, variant ('default' or 'destructive'), inset. data-highlighted while highlighted. |
ScMenuCheckboxItem | [scMenuCheckboxItem] | On or off (menuitemcheckbox), [(checked)]; the menu stays open. disabled, inset. |
ScMenuRadioGroup, ScMenuRadioItem | [scMenuRadioGroup], [scMenuRadioItem] | One of a group on (menuitemradio): [(value)] on the group, value on each item; the menu stays open. |
ScMenuItemIndicator | span[scMenuItemIndicator] | The check (your icon) of a checkbox or radio item, shown when it is on. |
ScMenuGroup, ScMenuLabel | [scMenuGroup], [scMenuLabel] | A titled section (role group), named by its label. |
ScMenuSubmenuIcon | svg[scMenuSubmenuIcon] | The icon (yours) of an item that opens a submenu: at its end, turned right to left. |
ScMenuSeparator | [scMenuSeparator] | A line between items. A key hint is yours: a scKbd in the item (⌘S) — the menu places it at the item’s end. |