Skip to content
Nizivo UI

Kbd

A keyboard shortcut drawn for both platforms, such as ⌘K and Ctrl+K; CSS shows the one for the current platform.

Server component, no client JS

Import

import { Kbd } from '@nizivo/react/kbd';

// Once per app (Getting started), after
// @nizivo/tokens/tokens.css and @nizivo/react/css/base.css
import '@nizivo/react/css/kbd.css';

Static or interactive

Server. It ships no client JavaScript when a Server Component renders it, in every Next.js build mode; its code is bundled only when a client component (a 'use client' file) imports it. It renders both platforms' keys and CSS shows one, from the data-nz-platform attribute that ThemeScript sets; without ThemeScript the Ctrl spelling shows. How to choose.

In a client app (a Vite or React Router single-page app, or a 'use client' file) it is an ordinary React component: event handlers, refs and state work as usual. In a client app.

Examples

Basic

Search with ⌘KCtrl+K, duplicate with ⌘⇧DCtrl+Shift+D, move with ↑↓ and close with esc.

import type { JSX } from 'react';
import { Kbd } from '@nizivo/react/kbd';

export function KbdExample(): JSX.Element {
  return (
    <p>
      Search with <Kbd keys="mod+k" />, duplicate with <Kbd keys="mod+shift+d" />, move with{' '}
      <Kbd>↑↓</Kbd> and close with <Kbd keys="esc" />.
    </p>
  );
}

Props

Server component Renders data-slot="kbd" with the class nz-kbd. Props: KbdProps. Source: src/kbd/kbd.tsx.

NameTypeDefaultDescription
childrenReactNode–

Literal key text, for example <Kbd>esc</Kbd> or <Kbd>↑↓</Kbd>.

keysstring–

A shortcut such as "mod+k" or "mod+shift+d", drawn for both platforms (⌘⇧D and Ctrl+Shift+D); CSS shows the one data-nz-platform names, and other when no ancestor sets it. mod is ⌘ on Apple platforms and Ctrl elsewhere; the plus key is plus ("mod+plus", or "mod++"). Replaces children.

renderRenderProp<Record<string, never>>–
  • Also takes every attribute of <kbd>; children is redeclared above. (ComponentPropsWithRef<"kbd">)

render takes an element, or, in client code, a function of the props and no state.

Other exports

KbdPlatform type

import type { KbdPlatform } from '@nizivo/react/kbd'

The data-platform values of the glyph spans; they match data-nz-platform (§8.3).

type KbdPlatform = "apple" | "other"

KbdProps type

import type { KbdProps } from '@nizivo/react/kbd'

The props of Kbd, listed above.

Data attributes and slots

Style parts by class (.nz-<slot>) and state by data attribute. Attribute meanings come from contracts/vocabulary.json.

SlotRendered byData attributes
kbd
.nz-kbd
Kbd
root (takes render)
none
kbd-glyphs
.nz-kbd-glyphs
Kbd
inner element (CSS only)
  • data-platform: "apple""other"
    Platform the glyph is drawn for; value set fixed in the Kbd manifest

CSS hooks

Set a hook on the component's class or any ancestor to restyle it without specificity games; leave it unset for the default shown.

HookDefaultRead as
--nz-kbd-bg--nz-bg-subtle
  • background on .nz-kbd
--nz-kbd-border--nz-border-default
  • border on .nz-kbd
--nz-kbd-fg--nz-text-secondary
  • color on .nz-kbd
--nz-kbd-radius--nz-radius-xs
  • border-radius on .nz-kbd

Layers: nz.components. Classes: .nz-kbd, .nz-kbd-glyphs.

Tokens this stylesheet reads (8)

--nz-bg-subtle, --nz-border-default, --nz-border-width-default, --nz-font-mono-m, --nz-radius-xs, --nz-space-1-5, --nz-text-secondary, --nz-tracking-mono-m

Accessibility

Nothing in this component takes focus or keyboard input.

Keyboard

None.

Figma

Node ids from design/component-map.json, which nz gen writes from component.json. The links open the Nizivo Figma library, which may ask you to sign in.

  • Canonical: none
  • Ghost masters: none

On this page