Kbd
Keyboard shortcut token for command hints and menus.
Kbd
Basic Usage
Kbd
Loading demo...
Interaction Contract
- The root element is
<kbd>, so it carries native keyboard-token semantics. size="sm"is the compact default for inline help and menu shortcuts.tone="primary"highlights product shortcuts without changing the slot content.- The component has no events and no internal state.
API
Props
| Prop | Type | Default | Description |
|---|---|---|---|
size | 'sm' | 'md' | 'sm' | Token size: sm (default) for inline help and menu shortcuts; md is larger for shortcuts shown on their own. |
tone | 'default' | 'primary' | 'default' | Visual tone: use primary only for the main shortcut on a page or command, at most one group per screen. |
Events
TxKbd does not emit component events.
Slots
| Slot | Props | Description |
|---|---|---|
default | - | Key label, such as ⌘, Ctrl, or K. |
Best Practices
- Render key combinations as separate
TxKbdtokens rather than one long string when spacing matters. - Keep labels platform-aware in host copy:
⌘for macOS,Ctrlfor Windows/Linux. - Use
tone="primary"sparingly for the main shortcut on a page or command. - Pair shortcut tokens with visible action text; shortcuts alone are not discoverable enough.
Review Notes
- Source:
packages/tuffex/packages/components/src/kbd/src/TxKbd.vueconfirms the semantic<kbd>root,size/toneclasses, and default slot-only content. - Verified coverage: Coverage:
packages/tuffex/packages/components/src/kbd/__tests__/kbd.test.tscovers rendered shortcut content, root tag, and variant classes. - Export:
packages/tuffex/packages/components/src/kbd/index.tswraps the component withwithInstalland exportsTxKbdInstance.
Source
查看源码
packages/tuffex/packages/components/src/kbd/index.ts