Skip to content

Add a Cmd+K hint to the docs search field - #519

Merged
eandreeva-twr merged 1 commit into
mainfrom
feat/search-cmdk-hint
Aug 18, 2026
Merged

Add a Cmd+K hint to the docs search field#519
eandreeva-twr merged 1 commit into
mainfrom
feat/search-cmdk-hint

Conversation

@eandreeva-twr

Copy link
Copy Markdown
Collaborator

The docs search has had a Cmd+K binding for a while, but nothing advertised it. This adds the usual badge inside the field.

What changed

A shortcut badge in the header search field. Renders ⌘K, swapped to Ctrl K off macOS by a small inline script so it resolves during parse — no flash of the wrong glyph. It fades out once the field has text and comes back when cleared, which is pure CSS (:not(:placeholder-shown)), so no extra JS listener and nothing to keep in sync with the existing Algolia input handler.

The badge is on the header field only. Below xl that field is hidden and search runs through the mobile overlay, whose trigger is a 20px icon with no room for a badge.

Cmd+K now works in the 1024–1280px band. It previously called .focus() on the header input, which in that band is in the DOM but hidden — so the shortcut silently did nothing. It now clicks whichever [data-search-trigger] is actually on screen, which keeps DocsLayout's delegated handler as the single place that knows how to open the overlay (focus timing, body scroll-lock, and Escape-to-close all come along unchanged).

Visibility is a box test rather than a hardcoded breakpoint, so it reads the same hidden xl:flex classes the layout already uses and won't drift if the breakpoint moves.

Placeholder shortened from "Search documentation..." to "Search docs...". I shortened tr, es, and fr to match; zh, ja, vi, and ru were already short. Those three could use a native-speaker glance.

Verified

Dev server, both themes:

Viewport Visible trigger Cmd+K result
1440px header field focuses the header input (unchanged)
1100px compact icon button overlay opens, focus moves to its input
375px mobile icon button overlay opens, focus moves to its input

Also checked: badge hides on typing and returns on clear; Ctrl K measures 44px and still fits inside the field's 64px right padding, so it can't collide with typed text; Escape closes the overlay and restores body scroll; repeat presses are idempotent; no console errors.

Show a keyboard-shortcut badge inside the header search input, so the
existing Cmd+K binding is discoverable rather than hidden. The badge
fades out while the field has text, and swaps to "Ctrl K" off macOS.

Only the header field carries it — below xl the field is hidden and
search runs through the mobile overlay, which has no room for a badge.

Also fix Cmd+K in the 1024-1280px band, where it focused an input that
is rendered but hidden. It now clicks whichever search trigger is
actually on screen, leaving DocsLayout's handler as the only place that
knows how to open the overlay.

Shorten the placeholder to "Search docs..." (en, tr, es, fr; the other
locales were already short).
@eandreeva-twr
eandreeva-twr merged commit eaa1da8 into main Aug 18, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant