Kbd
A key or a shortcut, as it is pressed. In the look of the app's style.
Usage
import { Component, ViewEncapsulation } from '@angular/core';import { ScKbd, ScKbdGroup } from '@semantic-components/ui';
@Component({ selector: 'app-kbd-usage-demo', imports: [ScKbd, ScKbdGroup], template: ` <div class="flex flex-col items-center gap-4"> <kbd scKbdGroup> <kbd scKbd>⌘<span class="sr-only"> Command</span></kbd> <kbd scKbd>⇧<span class="sr-only"> Shift</span></kbd> <kbd scKbd>⌥<span class="sr-only"> Option</span></kbd> <kbd scKbd>⌃<span class="sr-only"> Control</span></kbd> </kbd> <kbd scKbdGroup> <kbd scKbd>Ctrl</kbd> <span>+</span> <kbd scKbd>B</kbd> </kbd> <kbd scKbdGroup> <kbd scKbd>←<span class="sr-only"> Left</span></kbd> <kbd scKbd>↑<span class="sr-only"> Up</span></kbd> <kbd scKbd>↓<span class="sr-only"> Down</span></kbd> <kbd scKbd>→<span class="sr-only"> Right</span></kbd> </kbd> </div> `, host: { class: 'flex w-full justify-center' }, encapsulation: ViewEncapsulation.None,})export class KbdUsageDemo {}Anatomy
Every part is a directive on your kbd element; the keys are yours.
import { ScKbd, ScKbdGroup } from '@semantic-components/ui';<kbd scKbdGroup> <kbd scKbd>…</kbd> <kbd scKbd>…</kbd></kbd>Accessibility
- A key is read as text. A symbol alone can be unclear (⌘ is read as "place of interest", or not at all): write its name too, in sr-only text ("Command").
- A key beside the control it works shows the shortcut; give the control aria-keyshortcuts too, so screen readers say it.
Examples
Group
Use Ctrl + BCtrl + K to open the command palette
import { Component, ViewEncapsulation } from '@angular/core';import { ScKbd, ScKbdGroup } from '@semantic-components/ui';
/** Keys together in a scKbdGroup, here in a sentence. */@Component({ selector: 'app-group-kbd-demo', imports: [ScKbd, ScKbdGroup], template: ` <p class="text-muted-foreground text-sm"> UseIn a button
import { Component, ViewEncapsulation } from '@angular/core';import { ScButton, ScKbd } from '@semantic-components/ui';
/** A key at a button’s end (data-icon="inline-end": the button’s padding follows). */@Component({ selector: 'app-button-kbd-demo', imports: [ScButton, ScKbd], template: ` <button scButton variant="outline"> AcceptTooltip
import { Component, ViewEncapsulation } from '@angular/core';import { ScButton, ScControlGroup, ScKbd, ScTooltip, ScTooltipPortal, ScTooltipProvider, ScTooltipTrigger,} from '@semantic-components/ui';Input group
import { Component, ViewEncapsulation } from '@angular/core';import { ScInput, ScInputGroup, ScInputGroupAddon, ScKbd,} from '@semantic-components/ui';import { SiSearchIcon } from '@semantic-icons/lucide-icons';
/** The shortcut in a search field; some styles give the key the input’s background. */RTL
⌘ Command⇧ Shift⌥ Option⌃ ControlCtrl+B
import { Dir } from '@angular/cdk/bidi';import { Component, LOCALE_ID, ViewEncapsulation } from '@angular/core';import { ScKbd, ScKbdGroup } from '@semantic-components/ui';
/** In a right-to-left page: the keys in reading order, from the right. */@Component({ selector: 'app-rtl-kbd-demo', imports: [Dir, ScKbd, ScKbdGroup], template: ` <div dir="rtl" lang="ar" class="flex flex-col items-center gap-4">API reference
Each part takes class, merged over the style (cn: a later class wins).
| Part | Selector | Description |
|---|---|---|
ScKbd | kbd[scKbd] | A key: in a button (data-icon), an input group or a tooltip it takes their colours. |
ScKbdGroup | kbd[scKbdGroup] | Keys pressed together, side by side. |