Kbd
updatedCtrl+C, Ctrl+V. That's the whole career. A keyboard key, and a group of keys for a shortcut.
Press / to search, or Esc to close.
Open Props in the corner of the example to try size on the modifier keys.
xs to xl, md by default. Match the key to the text or control around it: xs in small print, lg and xl beside large buttons and inputs.
Installation
Usage
<script setup lang="ts">
import { Kbd, KbdGroup } from '@/components/ui/kbd'
</script>
<template>
<KbdGroup>
<Kbd>Ctrl</Kbd>
<Kbd>B</Kbd>
</KbdGroup>
</template>
Kbd is one key, and KbdGroup holds a whole shortcut. Separators like + or then are up to you: the group only spaces the keys.
Examples
Sequences
For a sequence, just list the keys. You know this one:
<template>
<KbdGroup>
<Kbd>↑</Kbd>
<Kbd>↑</Kbd>
<Kbd>↓</Kbd>
<Kbd>↓</Kbd>
<Kbd>←</Kbd>
<Kbd>→</Kbd>
<Kbd>←</Kbd>
<Kbd>→</Kbd>
<Kbd>B</Kbd>
<Kbd>A</Kbd>
</KbdGroup>
</template>
In a button
Inside a Button, or any other <button>, keys take the button's colours, so they fit every variant without extra classes.
A screen reader would read the keys as part of the label: "Save Ctrl S". Hide them and put the shortcut in aria-keyshortcuts instead:
<template>
<Button aria-keyshortcuts="Control+S">
Save
<KbdGroup aria-hidden="true">
<Kbd>Ctrl</Kbd>
<Kbd>S</Kbd>
</KbdGroup>
</Button>
</template>
aria-keyshortcuts only describes the shortcut. Listening for the keys is up to your app.
API Reference
Both parts take a class that merges with their own. Icons inside a key are 12px unless you size them.
Kbd
| Prop | Default | Type and description |
|---|---|---|
| size | "md" | KbdSizeFrom |
| Slot | Scope and description |
|---|---|
| default | {}The key: a label such as |
KbdGroup
| Slot | Scope and description |
|---|---|
| default | {}The keys of one shortcut, and any separators between them. |
Props
- size
"md" KbdSizeFromxstoxl: 16, 18, 20, 24 and 28px tall, with the label and any icon scaled to match.mdby default.
Slots
- default
{}The key: a label such asCtrl, a symbol such as⌘, or an icon.
Slots
- default
{}The keys of one shortcut, and any separators between them.
Data attributes
| data-slot | Attributes | Description |
|---|---|---|
| kbd | — | One key. |
| kbd-group | — | The keys of one shortcut. |