Skip to content
VenusUI
Get started

Keyboard

A compact Mac-style keyboard whose keys press down when clicked, light up as you type on your own keyboard, and can sound like a mechanical keyboard.

Preview

Installation

npx shadcn@latest add @venusui/keyboard

Run this in a project set up with shadcn. If you haven’t set it up yet, run npx shadcn@latest init first.

Files added to your project

Paths use the default shadcn aliases. The CLI follows the aliases in your components.json.

  • @/components/ui/keyboard.tsx

Usage

The code behind the preview above.

keyboard-demo.tsx

"use client"

import * as React from "react"

import { Keyboard, type KeyboardKeyPress, type KeyboardSound } from "@/components/ui/keyboard"
import { cn } from "@/lib/utils"

const SOUNDS: { value: KeyboardSound | "off"; label: string }[] = [
  { value: "off", label: "Off" },
  { value: "thock", label: "Thock" },
  { value: "clicky", label: "Clicky" },
]

export default function KeyboardDemo() {
  const [recent, setRecent] = React.useState<(KeyboardKeyPress & { id: number })[]>([])
  const [sound, setSound] = React.useState<KeyboardSound | "off">("thock")
  const nextId = React.useRef(0)

  return (
    <div className="flex w-full max-w-3xl flex-col items-center gap-6">
      <div className="flex w-full flex-wrap items-center justify-between gap-3">
        <p aria-live="polite" className="flex min-h-7 flex-wrap items-center gap-1.5 text-sm text-muted-foreground">
          {recent.length === 0
            ? "Click a key, or type on your keyboard."
            : recent.map((key) => (
                <kbd key={key.id} className="rounded-md border bg-muted px-1.5 py-0.5 font-sans text-xs text-foreground">
                  {key.name}
                </kbd>
              ))}
        </p>
        <div role="group" aria-label="Sound" className="flex shrink-0 items-center gap-0.5 rounded-lg border p-0.5 text-xs">
          {SOUNDS.map((option) => (
            <button
              key={option.value}
              type="button"
              aria-pressed={sound === option.value}
              onClick={() => setSound(option.value)}
              className={cn(
                "rounded-md px-2.5 py-1 outline-none focus-visible:ring-3 focus-visible:ring-ring/50",
                sound === option.value ? "bg-muted font-medium text-foreground" : "text-muted-foreground hover:text-foreground"
              )}
            >
              {option.label}
            </button>
          ))}
        </div>
      </div>
      <Keyboard
        sound={sound === "off" ? false : sound}
        onKeyPress={(key) => setRecent((all) => [...all, { ...key, id: nextId.current++ }].slice(-8))}
      />
    </div>
  )
}

API reference

PropTypeDefaultDescription
onKeyPress(key: KeyboardKeyPress) => void—Called for each press with the key's code (e.g. "KeyA"), name (e.g. "A") and source: "click" or "keyboard".
listenbooleantrueLight up keys as they are pressed on the user's real keyboard.
soundboolean | "thock" | "clicky"falseMechanical keyboard sound on each press and release: "thock" (deep, linear switches; true plays this) or "clicky" (bright click switches). Synthesized with the Web Audio API, so there are no audio files.

All <div> props, on the outer element.

Requirements

  • lucide-react for the function-row icons. The CLI installs it.
  • Tailwind CSS v4 (it uses container queries to scale with its container).

Customization

  • It fills its container's width up to about 52rem; wrap it in e.g. max-w-xl to make it smaller.
  • Keys use neutral grays in light and dark mode. Change the key and case colors in the className strings in keyboard.tsx.
  • The layout is the ROWS data at the top of the file. Each row adds up to 14.5 key units; keep that total if you change key widths.
  • Set listen={false} to show a keyboard that only responds to clicks, e.g. in a list of several.
  • Tune the sounds in SHAPES in keyboard.tsx: each is a few filtered noise bursts (the click and the plastic) and pitch-dropping tones (the bottom-out). Lower frequency values sound deeper.

Accessibility

  • The keyboard is a labelled group of real buttons, each named after its key (“Command”, “Left arrow”).
  • Tab enters the keyboard once; the arrow keys then move between keys by position and Enter or Space presses the focused key.
  • Caps Lock reports its state with aria-pressed and shows a light.
  • Sound is off by default and is never the only feedback: every press also moves the key. The press animation is instant when the user prefers reduced motion.

Troubleshooting

Keys don’t light up when I type.
Only keys on this layout light up, and not while focus is inside the keyboard itself (there the arrow keys move between keys). Check that listen isn’t false.
No sound in Safari or on iPhone.
Browsers allow audio only after the user interacts with the page; the first click enables it. Silent mode on iPhone also mutes Web Audio.
Unknown registry "@venusui"
Your shadcn CLI couldn’t find the namespace in the shadcn registry index. Use the latest CLI (npx shadcn@latest), install by URL, or register it with its address: npx shadcn@latest registry add @venusui=https://venusui.com/r/{name}.json.
No components.json found
Run npx shadcn@latest init in your project first.
Loading preview

Analog Clock

Data display

A station clock whose needle waits at twelve; drag the minute hand to set it by hand.

Loading preview

Bookshelf

Interactive

Books on a wooden shelf whose spines lift on hover and pull out when selected, with a matching cover.

Loading preview

Chat Thread

Data display

A messaging conversation that plays out with typing indicators; viewers can send replies too.