Components
Shortcut Tooltip
A tooltip that shows a keyboard shortcut.
SearchCtrlK
<ShortcutTooltip label="Search" keys={["⌘", "K"]} shortcut="Meta+K">
<button>Search</button>
</ShortcutTooltip>Installation
npx shadcn@latest add https://ui.zjkm.tech/r/shortcut-tooltip.jsonimport { 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
| Prop | Type | Default | Description |
|---|---|---|---|
label | string | The action's name. | |
keys | string[] | The keys to draw, e.g. ["⌘", "K"]. | |
shortcut | string | The shortcut for aria-keyshortcuts, e.g. "Meta+K". | |
children | ReactElement | One focusable element. | |
side | "top" | "bottom" | "top" | Where it appears. |
delay | number | 300 | Milliseconds before it shows on hover. |
With reduced motion, it appears without fading.