0.04K

Used to display textual user input from keyboard.

⌘ ⇧ ⌥ ⌃ Ctrl + B
import { Kbd, KbdGroup } from '@/components/ui/kbd';

<template>
  <div class="flex flex-col items-center gap-4">
    <KbdGroup>
      <Kbd>⌘</Kbd>
      <Kbd>⇧</Kbd>
      <Kbd>⌥</Kbd>
      <Kbd>⌃</Kbd>
    </KbdGroup>
    <KbdGroup>
      <Kbd>Ctrl</Kbd>
      <span>+</span>
      <Kbd>B</Kbd>
    </KbdGroup>
  </div>
</template>

Installation

pnpm dlx shadcn-ember@latest add kbd

Usage

import { Kbd } from '@/components/ui/kbd';
<Kbd>Ctrl</Kbd>

Examples

Group

Use the KbdGroup component to group keyboard keys together.

Use Ctrl + B Ctrl + K to open the command palette

import { Kbd, KbdGroup } from '@/components/ui/kbd';

<template>
  <div class="flex flex-col items-center gap-4">
    <p class="text-muted-foreground text-sm">
      Use
      <KbdGroup>
        <Kbd>Ctrl + B</Kbd>
        <Kbd>Ctrl + K</Kbd>
      </KbdGroup>
      to open the command palette
    </p>
  </div>
</template>

Button

Use the Kbd component inside a Button component to display a keyboard key inside a button.

import { Button } from '@/components/ui/button';
import { Kbd } from '@/components/ui/kbd';

<template>
  <div class="flex flex-wrap items-center gap-4">
    <Button @class="pr-2" @size="sm" @variant="outline">
      Accept
      <Kbd>⏎</Kbd>
    </Button>
    <Button @class="pr-2" @size="sm" @variant="outline">
      Cancel
      <Kbd>Esc</Kbd>
    </Button>
  </div>
</template>

Tooltip

You can use the Kbd component inside a Tooltip component to display a tooltip with a keyboard key.

import { Button } from '@/components/ui/button';
import { ButtonGroup } from '@/components/ui/button-group';
import { Kbd, KbdGroup } from '@/components/ui/kbd';
import {
  Tooltip,
  TooltipContent,
  TooltipTrigger,
} from '@/components/ui/tooltip';

<template>
  <div class="flex flex-wrap gap-4">
    <ButtonGroup>
      <Tooltip>
        <TooltipTrigger>
          <Button @size="sm" @variant="outline">
            Save
          </Button>
        </TooltipTrigger>
        <TooltipContent>
          <div class="flex items-center gap-2">
            Save Changes
            <Kbd>S</Kbd>
          </div>
        </TooltipContent>
      </Tooltip>
      <Tooltip>
        <TooltipTrigger>
          <Button @size="sm" @variant="outline">
            Print
          </Button>
        </TooltipTrigger>
        <TooltipContent>
          <div class="flex items-center gap-2">
            Print Document
            <KbdGroup>
              <Kbd>Ctrl</Kbd>
              <Kbd>P</Kbd>
            </KbdGroup>
          </div>
        </TooltipContent>
      </Tooltip>
    </ButtonGroup>
  </div>
</template>

Input Group

You can use the Kbd component inside a InputGroupAddon component to display a keyboard key inside an input group.

⌘ K
import {
  InputGroup,
  InputGroupAddon,
  InputGroupInput,
} from '@/components/ui/input-group';
import { Kbd } from '@/components/ui/kbd';

import SearchIcon from '~icons/lucide/search';

<template>
  <div class="flex w-full max-w-xs flex-col gap-6">
    <InputGroup>
      <InputGroupInput placeholder="Search..." />
      <InputGroupAddon>
        <SearchIcon />
      </InputGroupAddon>
      <InputGroupAddon @align="inline-end">
        <Kbd>⌘</Kbd>
        <Kbd>K</Kbd>
      </InputGroupAddon>
    </InputGroup>
  </div>
</template>

API Reference

Kbd

Use the Kbd component to display a keyboard key.

Prop Type Default
@class string ``
<Kbd>Ctrl</Kbd>

KbdGroup

Use the KbdGroup component to group Kbd components together.

Prop Type Default
@class string ``
<KbdGroup>
  <Kbd>Ctrl</Kbd>
  <Kbd>B</Kbd>
</KbdGroup>