Keyboard keys and shortcuts such as ⌘K.
- Search
- Command K⌘K
- Create an issue
- CC
- Go to inbox
- GGthenII
- Send a reply
- Command Return⌘↵
- Command menu
- Command Shift P⌘⇧P
import type { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Kbd } from "./ui/uicontext/components/Kbd.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { color, font, space } from "./ui/uicontext/components/tokens.stylex.ts"const styles = stylex.create({ list: { display: "grid", gridTemplateColumns: "minmax(0, 1fr) auto", alignItems: "center", columnGap: space.xl, rowGap: space.md, inlineSize: "min(100%, 22rem)", margin: 0 }, term: { margin: 0, fontSize: font.base, color: color.fg }, keys: { margin: 0, display: "flex", gap: space.xs, alignItems: "center", color: color.faint, fontSize: font.xs },})const shortcuts = [ { action: "Search", keys: ["mod+k"] }, { action: "Create an issue", keys: ["c"] }, { action: "Go to inbox", keys: ["g", "i"] }, { action: "Send a reply", keys: ["mod+enter"] }, { action: "Command menu", keys: ["mod+shift+p"] },]// a sequence (G then I) is two keycaps; a chord (⌘K) is one groupexport const ShortcutList = <M>(h: Html.H<M>) => h.dl.attrs(sx(styles.list)).children( shortcuts.flatMap((shortcut) => [ h.dt.key(`${shortcut.action}:t`).attrs(sx(styles.term)).children(shortcut.action), h.dd.key(`${shortcut.action}:d`).attrs(sx(styles.keys)).children( ...shortcut.keys.flatMap((keys, i) => (i === 0 ? [Kbd(h, keys)] : ["then", Kbd(h, keys)])), ), ]), )Installation
pnpm dlx shadcn@latest add checkfu/uicontext/kbdUsage
import { Kbd } from "./ui/uicontext/components/Kbd.ts"export const SearchHint = <M>(h: Html.H<M>) => h.p.children("Press ", Kbd(h, "mod+k", { size: "sm" }), " to search.")Examples
Mac and other platforms
The same keys as ⌘⇧P or Ctrl Shift P. Screen readers hear “Command Shift P”.
MacCommand Shift P⌘⇧P
Windows and LinuxControl Shift PCtrlShiftP
import type { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Kbd } from "./ui/uicontext/components/Kbd.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { color, font } from "./ui/uicontext/components/tokens.stylex.ts"const styles = stylex.create({ rows: { display: "grid", gap: 10 }, row: { display: "flex", alignItems: "center", gap: 10, fontSize: font.sm, color: color.muted },})// pass `mac` from the platform the browser reports (`isMac()`); screen readers hear the namesexport const Platforms = <M>(h: Html.H<M>) => h.div.attrs(sx(styles.rows)).children( h.div.attrs(sx(styles.row)).children("Mac", Kbd(h, "mod+shift+p", { mac: true })), h.div.attrs(sx(styles.row)).children("Windows and Linux", Kbd(h, "mod+shift+p", { mac: false })), )API reference
Options
| Name | Type | Default | Description |
|---|---|---|---|
size | "sm" | "md" | md | The keycap's size; md by default. |
tone | "default" | "inherit" | — | "inherit" takes the color of what it sits on, for a keycap inside a button |
mac | boolean | true | ⌘ ⌥ ⇧ on a Mac, Ctrl Alt Shift elsewhere; true by default |
style | Style | — | StyleX styles applied after the keycap’s own. |
Accessibility
- A combination is a
<kbd>of<kbd>s. The caps show symbols, and screen readers hear words instead: "Command K", never "⌘ K". modshows ⌘ on a Mac and Ctrl elsewhere, and is spoken to match.