opensourceui
GitHubTwitter/X
  1. Home
  2. Components
  3. Text
  4. Keyboard Shortcuts
Back to Text

Components / Text

Keyboard Shortcuts

Free Text React component — KeyboardShortcutsCard. MIT licensed, copy-paste ready for Next.js and Tailwind CSS.

Shortcut reference card with rendered key caps and a ⌘K header hint. Docs pages and onboarding modals use this constantly.

Preview

Shortcuts

Press ⌘K anywhere

Open command palette
⌘K
Save changes
⌘S
Undo last action
⌘Z
Quick actions
⌘⇧P
Close panel
Esc

Setup

How to use

Free for personal and commercial use. No UI attribution required. Include the MIT copyright notice when copying component source into your project. Read the MIT license.

  1. 1

    Run in your terminal:

    $npm install clsx tailwind-merge lucide-react
  2. 2

    Copy lib/cn.ts below. Skip if you already have cn().

  3. 3

    Copy the code below and create components/text/keyboard-shortcuts-card.tsx in your project.

  4. 4

    Import and render:

    Example

    import { KeyboardShortcutsCard } from "@/components/text/keyboard-shortcuts-card";

    <KeyboardShortcutsCard />

lib/cn.ts

1
2
3
4
5
6
import { type ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";
 
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}

components/text/keyboard-shortcuts-card.tsx

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import { forwardRef, type ComponentPropsWithoutRef } from "react";
 
import { cn } from "@/lib/cn";
 
import { Command } from "lucide-react";
 
export type KeyboardShortcut = {
keys: string[];
label: string;
};
 
export type KeyboardShortcutsCardProps = Readonly<
{
title?: string;
shortcuts?: KeyboardShortcut[];
hint?: string;
} & ComponentPropsWithoutRef<"div">
>;
 
const defaultShortcuts: KeyboardShortcut[] = [
{ keys: ["⌘", "K"], label: "Open command palette" },
{ keys: ["⌘", "S"], label: "Save changes" },
{ keys: ["⌘", "Z"], label: "Undo last action" },
{ keys: ["⌘", "⇧", "P"], label: "Quick actions" },
{ keys: ["Esc"], label: "Close panel" },
];
 
// Production-ready Keyboard Shortcuts component — styled with Tailwind CSS.
export const KeyboardShortcutsCard = forwardRef<
HTMLDivElement,
KeyboardShortcutsCardProps
>(
(
{
className,
title = "Shortcuts",
shortcuts = defaultShortcuts,
hint = "Press ⌘K anywhere",
...props
},
ref,
) => (
<div
ref={ref}
data-slot="keyboard-shortcuts-card"
className={cn(
"w-xs rounded-2xl border border-neutral-100 bg-white p-4 font-sans shadow-lg sm:p-5",
className,
)}
{...props}
>
<div
data-slot="keyboard-shortcuts-card-header"
className="mb-4 flex items-center gap-2"
>
<div className="flex h-8 w-8 items-center justify-center rounded-lg bg-neutral-900 text-white">
<Command size={14} />
</div>
<div>
<h4 className="text-sm font-bold text-neutral-900">{title}</h4>
<p className="text-[11px] text-neutral-400">{hint}</p>
</div>
</div>
 
<div data-slot="keyboard-shortcuts-card-list" className="space-y-2">
{shortcuts.map((shortcut) => (
<div
key={shortcut.label}
data-slot="keyboard-shortcuts-card-item"
className="flex items-center justify-between gap-3 rounded-xl bg-neutral-50 px-3 py-2"
>
<span className="min-w-0 truncate text-[13px] text-neutral-700">
{shortcut.label}
</span>
<div className="flex shrink-0 gap-1">
{shortcut.keys.map((key) => (
<kbd
key={key}
className="flex h-6 min-w-6 items-center justify-center rounded-md border border-neutral-100 bg-white px-1.5 font-mono text-[10px] font-medium text-neutral-600 shadow-sm"
>
{key}
</kbd>
))}
</div>
</div>
))}
</div>
</div>
),
);
 
KeyboardShortcutsCard.displayName = "KeyboardShortcutsCard";
PreviousNext

On this

page

Jump to a section on this page.

  • lib/cn.ts
  • components/text/keyboard-shortcuts-card.tsx

Sponsor spot · demo preview

Logo

Your brand name

Your tagline or category

A short pitch about your product or service goes here. This is a preview of how sponsor cards will look in this sidebar.

Your call to action

This slot is available. Sponsor Opensource UI and reach developers browsing components every day.