Skip to content

Site search: ⌘K / Ctrl+K from any page - #14

Merged
devmtnaing merged 2 commits into
mainfrom
cmdk-search
Sep 28, 2026
Merged

devmtnaing merged 2 commits into
mainfrom
cmdk-search

Conversation

@devmtnaing

Copy link
Copy Markdown
Owner

Adds a search dialog to every page, opened by a masthead button or ⌘K (Ctrl+K off macOS). It finds a problem by name, number, pattern or tag and opens its solution page, or LeetCode for a problem without a page yet. Until now, moving between problems meant going back to the home page. Nothing else is open, so this is against main.

How it works

  • The dialog is a native <dialog> with a combobox field: focus stays in the field, ↑ ↓ move the active result (wrapping at the ends), Enter opens it, and a click works too. Esc, a backdrop click or ⌘K again closes it, and focus returns to where it was.
  • Results with an empty field list the problems that have a solution page. When you type, every word must match. An exact problem number comes first, then titles that start with what you typed, then the home page's order.
  • The index is a static /search.json (11 KB), built from the new src/data/catalog.ts, which the home page now reads too. It's fetched the first time the dialog opens, or when the pointer reaches the button, so no page carries the list.
  • Without JavaScript, the button stays hidden and the home page's own search box does the job.
  • On phones, the button is icon-only and 40px on touch screens. The masthead gap drops from 10px to 8px so the bar stays on one line at 320px; with the new button it wrapped to 91px.
  • Lesson pages: the stepper already ignores key presses with modifiers, so the arrow keys and Space keep working, including right after the dialog closes.

Checked

  • A browser test covered every item above: Ctrl+K, focus, empty list, "two sum", "42" (Trapping Rain Water first), arrows and wrapping, no match, Esc returning focus to Next, arrows stepping again, Enter and click navigation, 320px and 400px, and light and dark themes.
  • axe finds no WCAG A/AA issues with the dialog open.
  • The audit now has a siteSearch check that guards the same things. npm run audit: passed, 46 pages. npm run check: 46 lessons, 0 failures.

A masthead button and ⌘K (Ctrl+K elsewhere) open a dialog that finds a
problem by name, number, pattern or tag and opens its solution page, or
LeetCode for one without a page yet. Until now, moving between problems
meant going back to the home page.

- SiteSearch.astro: a native <dialog> with a combobox field; ↑ ↓ move the
  active result, Enter opens it, Esc closes and gives focus back. Hidden
  without JavaScript, where the home page's search box does the job.
- /search.json, built from the new src/data/catalog.ts, which the home page
  now reads too; fetched on first open, so no page carries the list.
- the phone masthead's gap drops to 8px so the bar stays one line at 320px
- audit: Ctrl+K from a lesson, every lesson listed, "two sum" first, axe
  clean with the dialog open in both themes, Esc and Enter, one-line bar
@coderabbitai

coderabbitai Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: f9b2fee1-be93-4991-9d26-35713ac67b8f


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

🚀 Deploying Preview to Cloudflare 🚀

Preview Deployments by commit

Status Deployment URL Commit Updated (UTC) See this deployment's details
  • Build: Success ✅

View logs ↗
No Preview URL. Enable ↗ f437dd4 2026-09-28T12:13:31.941Z Visit the dashboard ↗
  • Build: Success ✅

View logs ↗
No Preview URL. Enable ↗ af582fe 2026-09-28T10:29:41.419Z Visit the dashboard ↗

The audit's one-line check failed in CI: with a fallback font (before the
web fonts load, or on Linux) brand, links, search and theme need 295px of
the 292px a 320px screen has. Under 375px the nav's "LeetCode" link, which
goes where the brand already does, steps aside; the bar then needs 223px.
@devmtnaing
devmtnaing merged commit 89ed063 into main Sep 28, 2026
7 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