Skip to Content
zjkm-ui
Components

Shortcut Tooltip

A tooltip that shows a keyboard shortcut.

Props
<ShortcutTooltip label="Search" keys={["⌘", "K"]} shortcut="Meta+K">
  <button>Search</button>
</ShortcutTooltip>

Installation

npx shadcn@latest add https://ui.zjkm.tech/r/shortcut-tooltip.json
import { ShortcutTooltip } from "@/components/shortcut-tooltip"

Using JavaScript? Set tsx: false in components.json and the CLI converts it.

New to shadcn? Run npx shadcn@latest init first. The CLI needs components.json and the @/ import alias.

Usage

A tooltip with an action's name and its keyboard shortcut, drawn as keys. It also sets aria-keyshortcuts on the trigger, so screen readers can announce the shortcut.

import { ShortcutTooltip } from "@/components/shortcut-tooltip";

export function SearchButton() {
  return (
    <ShortcutTooltip label="Search" keys={["⌘", "K"]} shortcut="Meta+K">
      <button>Search</button>
    </ShortcutTooltip>
  );
}

Props

PropTypeDefaultDescription
labelstringThe action's name.
keysstring[]The keys to draw, e.g. ["⌘", "K"].
shortcutstringThe shortcut for aria-keyshortcuts, e.g. "Meta+K".
childrenReactElementOne focusable element.
side"top" | "bottom""top"Where it appears.
delaynumber300Milliseconds before it shows on hover.

With reduced motion, it appears without fading.

On this page