Command
A search over commands: typing filters them, the arrows move the highlight, Enter runs it.
Usage
import { Component, ViewEncapsulation, signal } from '@angular/core';import { ScCommand, ScCommandEmpty, ScCommandGroup, ScCommandGroupLabel, ScCommandInput, ScCommandInputGroup, ScCommandItem, ScCommandList, ScCommandSeparator, ScCommandStatus, ScFrame, ScKbd,} from '@semantic-components/ui';import { SiCalculatorIcon, SiCalendarIcon, SiCreditCardIcon, SiSearchIcon, SiSettingsIcon, SiSmileIcon, SiUserIcon,} from '@semantic-icons/lucide-icons';
/** A search over commands, in groups: typing filters them, the arrows move the highlight, Enter runs it. */@Component({ selector: 'app-command-usage-demo', imports: [ ScCommand, ScCommandEmpty, ScCommandGroup, ScCommandGroupLabel, ScCommandInput, ScCommandInputGroup, ScCommandItem, ScCommandList, ScCommandSeparator, ScKbd, ScCommandStatus, ScFrame, SiCalculatorIcon, SiCalendarIcon, SiCreditCardIcon, SiSearchIcon, SiSettingsIcon, SiSmileIcon, SiUserIcon, ], template: ` <div class="flex w-full max-w-sm flex-col gap-3"> <div scCommand #cmd="scCommand" scFrame> <div scCommandInputGroup> <svg siSearchIcon></svg> <input scCommandInput placeholder="Type a command or search..." aria-label="Search commands" /> </div> <div scCommandList aria-label="Commands"> <div scCommandEmpty>No results found.</div> <div scCommandGroup> <div scCommandGroupLabel>Suggestions</div> <div scCommandItem (select)="ran('Calendar')"> <svg siCalendarIcon></svg> <span>Calendar</span> </div> <div scCommandItem (select)="ran('Search Emoji')"> <svg siSmileIcon></svg> <span>Search Emoji</span> </div> <div scCommandItem disabled (select)="ran('Calculator')"> <svg siCalculatorIcon></svg> <span>Calculator</span> </div> </div> <div scCommandSeparator></div> <div scCommandGroup> <div scCommandGroupLabel>Settings</div> <div scCommandItem (select)="ran('Profile')"> <svg siUserIcon></svg> <span>Profile</span> <kbd scKbd>⌘P</kbd> </div> <div scCommandItem (select)="ran('Billing')"> <svg siCreditCardIcon></svg> <span>Billing</span> <kbd scKbd>⌘B</kbd> </div> <div scCommandItem (select)="ran('Settings')"> <svg siSettingsIcon></svg> <span>Settings</span> <kbd scKbd>⌘S</kbd> </div> </div> </div> <div scCommandStatus>{{ cmd.count() }} results</div> </div> <p class="text-muted-foreground text-sm" aria-live="polite"> @if (last()) { Ran {{ last() }}. } </p> </div> `, host: { class: 'flex w-full justify-center' }, encapsulation: ViewEncapsulation.None,})export class CommandUsageDemo { private readonly last = signal('');
private ran(name: string): void { this.last.set(name); }}Anatomy
A search and a list of your items, in groups. It filters them itself — their text, value and keywords — and keeps your order; a group with no match hides, the lines between groups while searching. In a dialog, on the dialog itself.
import { ScCommand, ScCommandInputGroup, ScCommandInput, ScCommandList, ScCommandEmpty, ScCommandGroup, ScCommandGroupLabel, ScCommandItem, ScCommandSeparator, ScCommandStatus, ScCommandDialog,} from '@semantic-components/ui';<div scCommand #cmd="scCommand"> <div scCommandInputGroup> <svg siSearchIcon></svg> <input scCommandInput aria-label="…" /> </div> <div scCommandList aria-label="…"> <div scCommandEmpty>…</div> <div scCommandGroup> <div scCommandGroupLabel>…</div> <div scCommandItem (select)="…"> … <kbd scKbd>…</kbd> </div> </div> <div scCommandSeparator></div> </div> <div scCommandStatus>{{ cmd.count() }} results</div></div>Accessibility
- The search is a combo box and the items a list box: focus stays in the search while the highlight moves (aria-activedescendant). Name both (aria-label).
- Up and Down move the highlight (round from the last item with loopFocus), Ctrl + N and Ctrl + P (or J and K) too; Alt + Up and Alt + Down jump between groups; Enter runs the highlighted item. Home and End stay the search's. The first match is always highlighted.
- Groups are named by their heading; disabled items are skipped.
- The status, read and not shown, announces your text about the results as they change ("3 results").
- In a dialog: focus in the search when it opens, Escape closes it, focus back to what opened it. Write its title and description (sr-only).
Examples
Basic
import { Component, ViewEncapsulation, signal } from '@angular/core';import { ScButton, ScCommand, ScCommandDialog, ScCommandEmpty, ScCommandGroup, ScCommandGroupLabel, ScCommandInput, ScCommandInputGroup,Shortcuts
import { Component, ViewEncapsulation, signal } from '@angular/core';import { ScButton, ScCommand, ScCommandDialog, ScCommandEmpty, ScCommandGroup, ScCommandGroupLabel, ScCommandInput, ScCommandInputGroup,Groups
import { Component, ViewEncapsulation, signal } from '@angular/core';import { ScButton, ScCommand, ScCommandDialog, ScCommandEmpty, ScCommandGroup, ScCommandGroupLabel, ScCommandInput, ScCommandInputGroup,Scrollable
import { Component, ViewEncapsulation, signal } from '@angular/core';import { ScButton, ScCommand, ScCommandDialog, ScCommandEmpty, ScCommandGroup, ScCommandGroupLabel, ScCommandInput, ScCommandInputGroup,Dialog
The key is TanStack Hotkeys' (injectHotkey, with provideHotkeys() in your app config): install it where you use it.
Press Ctrl+J or
import { injectFormatForDisplay, injectHotkey,} from '@tanstack/angular-hotkeys';import { Component, ViewEncapsulation, signal } from '@angular/core';import { ScButton, ScCommand, ScCommandDialog, ScCommandEmpty,Keywords
No results found.
Settings
Profile
Billing
Settings
3 results
import { Component, ViewEncapsulation, signal } from '@angular/core';import { ScCommand, ScCommandEmpty, ScCommandGroup, ScCommandGroupLabel, ScCommandInput, ScCommandInputGroup, ScCommandItem, ScCommandList,Async search
Countries
Searching…
import { Component, ViewEncapsulation, effect, signal } from '@angular/core';import { ScCommand, ScCommandEmpty, ScCommandGroup, ScCommandGroupLabel, ScCommandInput, ScCommandInputGroup, ScCommandItem, ScCommandList,Pages
No results found.
Actions
Search projects…
New project
2 results
import { Component, ViewEncapsulation, signal } from '@angular/core';import { ScCommand, ScCommandEmpty, ScCommandGroup, ScCommandGroupLabel, ScCommandInput, ScCommandInputGroup, ScCommandItem, ScCommandList,Links
import { Component, ViewEncapsulation, signal } from '@angular/core';import { RouterLink } from '@angular/router';import { ScCommand, ScCommandEmpty, ScCommandGroup, ScCommandGroupLabel, ScCommandInput, ScCommandInputGroup, ScCommandItem,RTL
لم يتم العثور على نتائج.
اقتراحات
التقويم
البحث عن رمز تعبيري
الآلة الحاسبة
الإعدادات
الملف الشخصي⌘P
الفوترة⌘B
الإعدادات⌘S
6 نتائج
import { Dir } from '@angular/cdk/bidi';import { Component, LOCALE_ID, ViewEncapsulation } from '@angular/core';import { ScCommand, ScCommandEmpty, ScCommandGroup, ScCommandGroupLabel, ScCommandInput, ScCommandInputGroup, ScCommandItem,API reference
Each part takes class, merged over the style (cn: a later class wins).
| Part | Selector | Description |
|---|---|---|
ScCommand | div[scCommand] | The command: it filters its items by the search. filter (text, search, keywords) => boolean, shouldFilter (off: yours, an async search), loopFocus, vimBindings, highlightItemOnHover. exportAs scCommand: count(), active(), search(). |
ScCommandInputGroup | div[scCommandInputGroup] | Around the search: your search icon (an SVG, first) and the input, in the input group's look. |
ScCommandInput | input[scCommandInput] | The search (role combobox, aria-activedescendant): [(value)] is its text; the keys move the highlight and run it. Name it. |
ScCommandList | div[scCommandList] | The items (role listbox), scrolling past its height, the highlighted one kept in view; its scrollbar shown (hideScrollbar hides it, as shadcn). Name it. |
ScCommandEmpty | div[scCommandEmpty] | Your text when no item shows. |
ScCommandGroup, ScCommandGroupLabel | div[scCommandGroup], [scCommandGroupLabel] | Related items (role group), named by the label; hidden while none of its items shows. |
ScCommandItem | div[scCommandItem], a[scCommandItem] | A command (role option): (select) on Enter or a click — a link is followed. value (what the search matches, its text when not set), keywords, disabled, forceMount (shown whatever the search). data-selected while highlighted. |
ScCommandSeparator | div[scCommandSeparator] | A line between groups, hidden while searching; decorative. |
ScCommandStatus | div[scCommandStatus] | Read, not shown (a polite live region): your text about the results, outside the list. |
ScCommandDialog | div[scCommandDialog] | On the scDialog a command opens in: no padding, the style's corners; its items' corners follow. |