The strip of keys at the foot of a palette or a viewer, such as ↑ ↓ Move, hidden on touch screens.
- 2.1 kB JS 2.9 kB CSS gzipped
- No serious axe issues
- Server-rendered, hydrates
- 44px touch targets
- Right-to-left
- 10 tests
- ENG-2140 Exports fail for large workspaces
- Q1 onboarding revamp
- Priya Raman
- Up arrow or Down arrow: Move
- Return: Open
- Command Return: Open in new tab
- Escape: Close
import type { Html } from "effect/ui/html"import * as stylex from "@stylexjs/stylex"import { KeyHints } from "./ui/uicontext/components/KeyHints.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { color, corner, font, space, stroke } from "./ui/uicontext/components/tokens.stylex.ts"const styles = stylex.create({ palette: { inlineSize: "min(100%, 32rem)", borderWidth: stroke.hairline, borderStyle: "solid", borderColor: color.line, borderRadius: corner.popover, backgroundColor: color.panel, overflow: "hidden" }, search: { paddingBlock: space.md, paddingInline: space.md, fontSize: font.base, color: color.muted, borderBlockEndWidth: stroke.hairline, borderBlockEndStyle: "solid", borderBlockEndColor: color.line }, list: { display: "grid", margin: 0, padding: space.xs, listStyle: "none", fontSize: font.sm }, item: { paddingBlock: space.sm, paddingInline: space.sm, borderRadius: corner.control }, active: { backgroundColor: color.selected },})// the foot of a command palette: what the keys do while it's openexport const PaletteFooter = <M>(h: Html.H<M>) => h.div.attrs(sx(styles.palette)).children( h.div.attrs({ "aria-hidden": "true", ...sx(styles.search) }).children("Search issues, projects and people…"), h.ul.attrs({ "aria-label": "Recent", ...sx(styles.list) }).children( h.li.attrs(sx(styles.item, styles.active)).children("ENG-2140 Exports fail for large workspaces"), h.li.attrs(sx(styles.item)).children("Q1 onboarding revamp"), h.li.attrs(sx(styles.item)).children("Priya Raman"), ), KeyHints(h, { variant: "bar", touch: true, hints: [ { keys: ["up", "down"], label: "Move" }, { keys: "enter", label: "Open" }, { keys: "mod+enter", label: "Open in new tab" }, { keys: "esc", label: "Close" }, ], }), )When to use
The strip of keys at the foot of a palette or a viewer, such as ↑ ↓ Move, hidden on touch screens. Use Kbd instead when you show one shortcut beside its command.
Usage
import { KeyHints } from "./ui/uicontext/components/KeyHints.ts"export const Footer = <M>(h: Html.H<M>) => KeyHints(h, { hints: [{ keys: ["up", "down"], label: "Move" }, { keys: "enter", label: "Open" }, { keys: "esc", label: "Close" }] })Examples
Hidden on touch screens
Without touch, the strip hides on phones and tablets, where nobody presses these keys.
3 / 12
- Left arrow or Right arrow: Previous and next
- Space: Zoom
- D: Download
import type { Html } from "effect/ui/html"import * as stylex from "@stylexjs/stylex"import { KeyHints } from "./ui/uicontext/components/KeyHints.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { color, corner, font, space } from "./ui/uicontext/components/tokens.stylex.ts"const styles = stylex.create({ viewer: { display: "grid", gap: space.sm, inlineSize: "min(100%, 34rem)" }, stage: { display: "grid", placeItems: "center", aspectRatio: "16 / 9", borderRadius: corner.card, backgroundColor: color.app, color: color.muted, fontSize: font.sm },})// a photo viewer's hints, at the end of the row; they hide on a phone, where people swipeexport const ViewerHints = <M>(h: Html.H<M>) => h.div.attrs(sx(styles.viewer)).children( h.div.attrs({ role: "img", "aria-label": "Site visit, photo 3 of 12", ...sx(styles.stage) }).children("3 / 12"), KeyHints(h, { align: "end", label: "Viewer shortcuts", hints: [ { keys: ["left", "right"], label: "Previous and next" }, { keys: "space", label: "Zoom" }, { keys: "d", label: "Download" }, ], }), )API reference
Options
| Name | Type | Default | Description |
|---|---|---|---|
hintsrequired | KeyHint[] | — | The hints, in order. |
label | string | — | Names the list for a screen reader; "Keyboard shortcuts" by default. |
variant | "plain" | "bar" | — | bar draws a line above, for the foot of a dialog or a panel. |
align | "start" | "end" | start | Which end of the row the hints sit at; start by default. |
touch | boolean | — | Keeps the strip on touch screens too, for a tablet with a keyboard. |
mac | boolean | true | ⌘ on a Mac, Ctrl elsewhere; true by default. |
style | Style | — | — |
Installation
pnpm dlx shadcn@latest add checkfu/uicontext/key-hints