Hulian UIv0.93.5413 components0 components
  • Start
  • Components
  • Blocks
  • Pages
  • Demos
  • Changelog
ChineseEnglish
  • ComponentsComponents
  • ThemeTheme

Text

  • Text
  • Heading
  • SectionHeader
  • Prose
  • Markdown
  • Formula
  • AuroraText
  • LineShadowText
  • AnimatedShinyText
  • AnimatedGradientText
  • WordRotate
  • TypingAnimation
  • SparklesText
  • SplitText
  • BlurText
  • FlipText
  • TextReveal
  • DecryptedText
  • GlitchText
  • CircularText
  • ScrollReveal
  • TrueFocus
  • ASCIIText
  • CurvedLoop
  • FallingText
  • FuzzyText
  • ScrambledText
  • ScrollFloat
  • ScrollVelocity
  • Shuffle
  • TextCursor
  • TextPressure
  • VariableProximity

Code

  • Code
  • CodeBlock
  • Snippet
  • CodeDiff
  • Kbd

Kbd

kbd

Displays keyboard keys or shortcuts with inline keycap styling.

Usage

Single button

Wraps a single key name and renders it as a bordered keycap style.

Esc
tsx
<Kbd>Esc</Kbd>

Primary key cap

Use tone="primary" for a page's main shortcut (the top-bar search, a command palette entry): a brand subtle fill with a brand border that follows the theme color. KbdGroup passes its tone to every key cap.

⌘K⌘+K
tsx
<Kbd tone="primary">⌘K</Kbd>
<KbdGroup keys={["⌘", "K"]} tone="primary" />

Key combination

KbdGroup owns the gap and the separator, joining keys with + by default.

⌘+K
tsx
<KbdGroup keys={["⌘", "K"]} />

Custom separator, or none

separator accepts any node; pass null to keep the spacing without a symbol.

⌘·⇧·PGT
tsx
<KbdGroup keys={["⌘", "⇧", "P"]} separator="·" />
<KbdGroup keys={["G", "T"]} separator={null} />

Accessible name

label gives the whole combination one accessible name, and the separator itself stays out of the accessibility tree.

⌘+K
tsx
<KbdGroup keys={["⌘", "K"]} label="Open the command panel" />

Lay out the keycaps yourself

Switch to children when one key needs its own styling or content; the separators are still inserted.

⌘+S
tsx
<KbdGroup label="Save">
  <Kbd className="min-w-8">⌘</Kbd>
  <Kbd>S</Kbd>
</KbdGroup>

Embed text

The shortcut keys are shown in the text, and the keycaps are aligned with the text baseline.

Press ⌘+S to save
tsx
<span className="text-sm text-muted-foreground">
  Press <KbdGroup keys={["⌘", "S"]} label="Save" /> to save
</span>

When to use

Use Kbd to label an individual key such as Esc, ⌘, or K. Wrap key combinations such as ⌘ + K in KbdGroup from the same directory: it owns the gap, draws the separator, and gives the whole combination one accessible name. Both work in server components. Use CodeBlock or Snippet for code instead.

Import

ts
import { Kbd, KbdGroup } from "@hulianui/ui"

Props

NameTypeDefaultDescription
tone"default" | "primary""default"Color tone: neutral gray by default; primary uses the brand subtle fill and border for a page's main shortcut (the ⌘K search trigger, a command palette entry) and follows the theme color
...HTMLAttributesHTMLAttributes<HTMLElement>-supports <kbd> native attributes (className, style, etc.)

KbdGroup Props

NameTypeDefaultDescription
keysReactNode[]-Key names, each wrapped in a Kbd. The usual way to write a combination
separatorReactNode"+"Separator between keys. Decorative only (aria-hidden, never announced). Pass null to keep the spacing without drawing a symbol
labelstring-Accessible name for the whole combination, such as "Open command palette". role="group" is added only when it is present
tone"default" | "primary""default"Passed to every key cap generated from keys; the separator follows the color. When you pass children, set tone on each Kbd yourself
...HTMLAttributesHTMLAttributes<HTMLSpanElement>-supports native attributes of the wrapping <span>. The rest spread comes first, so the role and aria-label the component computes win (see Usage guidelines)

Slots

SlotTypeDescription
childrenReactNodeKey content for Kbd. On KbdGroup it means you lay out the keycaps yourself, and keys is ignored

Usage guidelines

  • One Kbd renders one keycap and never adds a +. Reach for KbdGroup instead of hand-rolling inline-flex + gap + separator at every call site, otherwise the spacing and separator styling drift apart across the app.
  • Without label, KbdGroup adds no role="group" and a screen reader announces the keycaps as unrelated fragments. Nothing about the rendered output looks different, which is exactly why this step gets skipped: whenever the combination stands for a concrete action, put that action name in label.
  • When both children and keys are present only children is rendered; keys is ignored, because honouring both has no sensible meaning.
  • A role you pass cannot override the component's own role="group". The rest spread comes first on the root node, see consuming.md §7. Without label the component claims no role, so whatever you pass is what you get.
  • No symbol mapping is built in (Meta → ⌘, Ctrl → ⌃, and so on). How a key should read depends on the platform detection and wording rules of the consuming app, so a built-in table would guess wrong in any cross-platform product.

Related

Code · CodeBlock · Snippet · CodeDiff · Text · Heading

PreviousCodeDiffTypographyNextASCIIText

On this page

  • Usage
  • Documentation
    • When to use
    • Import
    • Props
    • Slots
    • Usage guidelines
    • Related