Context Menu
A menu at the pointer, opened by a right-click on an area — a long press on touch, Shift + F10 or the Menu key on the focused area. In the look of the app's style.
Usage
import { Component, ViewEncapsulation, signal } from '@angular/core';import { ScContextMenu, ScContextMenuTrigger, ScFrame, ScKbd, ScMenu, ScMenuCheckboxItem, ScMenuContent, ScMenuGroup, ScMenuItem, ScMenuItemIndicator, ScMenuLabel, ScMenuPortal, ScMenuRadioGroup, ScMenuRadioItem, ScMenuSeparator, ScMenuSubmenuIcon,} from '@semantic-components/ui';import { SiCheckIcon, SiChevronRightIcon } from '@semantic-icons/lucide-icons';
@Component({ selector: 'app-context-menu-usage-demo', imports: [ ScContextMenu, ScContextMenuTrigger, ScFrame, ScMenuSubmenuIcon, ScMenu, ScMenuCheckboxItem, ScMenuContent, ScMenuGroup, ScMenuItem, ScMenuItemIndicator, ScMenuLabel, ScMenuPortal, ScMenuRadioGroup, ScMenuRadioItem, ScMenuSeparator, ScKbd, SiCheckIcon, SiChevronRightIcon, ], template: ` <div scContextMenu class="w-full max-w-xs"> <div scContextMenuTrigger scFrame class="flex aspect-video w-full items-center justify-center text-sm" > <span class="hidden pointer-fine:inline-block">Right click here</span> <span class="hidden pointer-coarse:inline-block">Long press here</span> </div> <ng-template scMenuPortal> <div scMenu class="w-48"> <ng-template scMenuContent> <div scMenuGroup> <div scMenuItem value="Back"> Back <kbd scKbd>⌘[</kbd> </div> <div scMenuItem value="Forward" [disabled]="true"> Forward <kbd scKbd>⌘]</kbd> </div> <div scMenuItem value="Reload"> Reload <kbd scKbd>⌘R</kbd> </div> <div scMenuItem value="More Tools"> More Tools <svg siChevronRightIcon scMenuSubmenuIcon></svg> <ng-template scMenuPortal> <div scMenu class="w-44"> <ng-template scMenuContent> <div scMenuGroup> <div scMenuItem value="Save Page...">Save Page...</div> <div scMenuItem value="Create Shortcut..."> Create Shortcut... </div> <div scMenuItem value="Name Window..."> Name Window... </div> </div> <div scMenuSeparator></div> <div scMenuGroup> <div scMenuItem value="Developer Tools"> Developer Tools </div> </div> <div scMenuSeparator></div> <div scMenuGroup> <div scMenuItem value="Delete" variant="destructive"> Delete </div> </div> </ng-template> </div> </ng-template> </div> </div> <div scMenuSeparator></div> <div scMenuGroup> <div scMenuCheckboxItem [(checked)]="bookmarks"> <span scMenuItemIndicator><svg siCheckIcon></svg></span> Show Bookmarks </div> <div scMenuCheckboxItem [(checked)]="fullUrls"> <span scMenuItemIndicator><svg siCheckIcon></svg></span> Show Full URLs </div> </div> <div scMenuSeparator></div> <div scMenuGroup> <div scMenuRadioGroup [(value)]="person"> <div scMenuLabel>People</div> <div scMenuRadioItem value="pedro"> <span scMenuItemIndicator><svg siCheckIcon></svg></span> Pedro Duarte </div> <div scMenuRadioItem value="colm"> <span scMenuItemIndicator><svg siCheckIcon></svg></span> Colm Tuite </div> </div> </div> </ng-template> </div> </ng-template> </div> `, host: { class: 'flex w-full justify-center' }, encapsulation: ViewEncapsulation.None,})export class ContextMenuUsageDemo { private readonly bookmarks = signal(true); private readonly fullUrls = signal(false); private readonly person = signal('pedro');}Anatomy
The context menu holds the area (the trigger) and the menu, in a portal as the Menu's: rendered while it is open. The menu is made of the Menu's parts, which take the context menu's look in it. The area's look and text are yours.
import { ScContextMenu, ScContextMenuTrigger, ScMenuPortal, ScMenu, ScMenuContent, ScMenuGroup, ScMenuItem, ScMenuSeparator,} from '@semantic-components/ui';<div scContextMenu> <div scContextMenuTrigger>…</div> <ng-template scMenuPortal> <div scMenu> <ng-template scMenuContent> <div scMenuGroup> <div scMenuItem value="…">…</div> </div> <div scMenuSeparator></div> …the Menu’s other parts… </ng-template> </div> </ng-template></div>Keyboard
- The area is focusable: Shift + F10 or the Menu key opens the menu on it, with its first item highlighted. A right-click opens it with nothing highlighted, until the pointer moves or a key is pressed.
- In the menu, the Menu's keys: the arrows move, a submenu opens toward the reading end, Enter or Space chooses.
- Escape, a click outside or a choice closes it; focus goes back to the area.
Examples
Basic
Right click hereLong press here
import { Component, ViewEncapsulation } from '@angular/core';import { ScContextMenu, ScContextMenuTrigger, ScFrame, ScMenu, ScMenuContent, ScMenuGroup, ScMenuItem, ScMenuPortal,Submenu
Right click hereLong press here
import { Component, ViewEncapsulation } from '@angular/core';import { ScContextMenu, ScContextMenuTrigger, ScFrame, ScKbd, ScMenu, ScMenuContent, ScMenuGroup, ScMenuItem,Shortcuts
Right click hereLong press here
import { Component, ViewEncapsulation } from '@angular/core';import { ScContextMenu, ScContextMenuTrigger, ScFrame, ScKbd, ScMenu, ScMenuContent, ScMenuGroup, ScMenuItem,Groups
Right click hereLong press here
import { Component, ViewEncapsulation } from '@angular/core';import { ScContextMenu, ScContextMenuTrigger, ScFrame, ScKbd, ScMenu, ScMenuContent, ScMenuGroup, ScMenuItem,Icons
Right click hereLong press here
import { Component, ViewEncapsulation } from '@angular/core';import { ScContextMenu, ScContextMenuTrigger, ScFrame, ScMenu, ScMenuContent, ScMenuGroup, ScMenuItem, ScMenuPortal,Checkboxes
Right click hereLong press here
import { Component, ViewEncapsulation, signal } from '@angular/core';import { ScContextMenu, ScContextMenuTrigger, ScFrame, ScMenu, ScMenuCheckboxItem, ScMenuContent, ScMenuGroup, ScMenuItemIndicator,Radio
Right click hereLong press here
import { Component, ViewEncapsulation, signal } from '@angular/core';import { ScContextMenu, ScContextMenuTrigger, ScFrame, ScMenu, ScMenuContent, ScMenuGroup, ScMenuItemIndicator, ScMenuLabel,Destructive
Right click hereLong press here
import { Component, ViewEncapsulation } from '@angular/core';import { ScContextMenu, ScContextMenuTrigger, ScFrame, ScMenu, ScMenuContent, ScMenuGroup, ScMenuItem, ScMenuPortal,Sides
Right click (top)Long press (top)
Right click (end)Long press (end)
Right click (bottom)Long press (bottom)
Right click (start)Long press (start)
import { Component, ViewEncapsulation } from '@angular/core';import { ScContextMenu, ScContextMenuTrigger, ScFrame, ScMenu, ScMenuContent, ScMenuGroup, ScMenuItem, ScMenuPortal,RTL
انقر بزر الماوس الأيمن هنااضغط مطولاً هنا
import { Dir } from '@angular/cdk/bidi';import { Component, LOCALE_ID, ViewEncapsulation, signal } from '@angular/core';import { ScContextMenu, ScContextMenuTrigger, ScFrame, ScKbd, ScMenu, ScMenuCheckboxItem, ScMenuContent,API reference
Each part takes class, merged over the style (cn: a later class wins). The menus' parts are the Menu's (see Menu).
| Part | Selector | Description |
|---|---|---|
ScContextMenu | div[scContextMenu] | Holds the area and its menu: catches the right-click and opens the menu there. [(open)]; side: 'inline-end' (default), 'inline-start', 'top' or 'bottom' — logical; 'left' or 'right' stay put right to left. |
ScContextMenuTrigger | [scContextMenuTrigger] | The area: focusable (Shift+F10, the Menu key), no text selection on a long press. Its look is yours. |
ScMenuPortal, ScMenu, ScMenuItem… | ng-template[scMenuPortal], div[scMenu]… | The menu and its parts: the Menu’s, in the context menu’s look. |