HextaUI

Kbd: In a button

Inside a button, the cap takes its colors from the button's text, so it fits every variant.

import { IconSearch } from "@tabler/icons-react"

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

export function KbdButton() {
  return (
    <div className="flex flex-wrap items-center justify-center gap-3">
      <Button variant="outline">
        <IconSearch data-icon="inline-start" />
        Search
        <Kbd keys="mod+k" />
      </Button>
      <Button>
        Save
        <Kbd keys="mod+s" />
      </Button>
      <Button variant="ghost">
        Undo
        <Kbd keys="mod+z" variant="flat" />
      </Button>
    </div>
  )
}

This adds the example as components/examples/kbd/button.tsx, together with the Kbd component and the HextaUI theme tokens it needs.

pnpm dlx shadcn@latest add https://hextaui.com/r/kbd-button.json

To add only the component, follow the Kbd installation.

Props in this example

The Kbd props this example sets, from the API reference.

PropTypeDefault
keysKeys joined with +, like "mod+shift+p". mod is ⌘ on Apple devices and Ctrl elsewhere. Names such as alt, enter, escape, up and space become symbols or short words, and get a spoken name for screen readers.
string–
variantInherited from KbdGroup when unset.
"keycap" | "flat""keycap"

Every prop is in the Kbd API reference.

See them all, with keyboard support and accessibility notes, on the Kbd page.