Skip to content

Focus the API search box when "/" is pressed - #4511

Merged
technige merged 2 commits into
mainfrom
api-explorer-slash-focus-search
Oct 19, 2026
Merged

technige merged 2 commits into
mainfrom
api-explorer-slash-focus-search

Conversation

@technige

@technige technige commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Pressing / outside a text field now focuses the search box in the API sidebar, and Esc clears it and drops focus, as on GitHub. The placeholder reads Press ❲/❳ to find API.

Affects: Site UI, API reference

Prompt summary: Make the API Explorer's jump-to-page box behave like GitHub's search box. Typing / focuses it, and the placeholder tells readers so. elastic/docs-eng-team#1096 tracks the request.

For full context, this intends to result in the following functionality:

  • Ctrl+F - find in page, built into the browser
  • Ctrl+K - generally mapped to broader search functionality (website search, browser search)
  • / - used in GitHub and similar for searching for code or code artifacts - originates from vim, etc - mapped here to the functionality to search within the API content

Why

The search box in the API sidebar has no keyboard shortcut, and nothing in the box says one could exist. Readers click into it every time. GitHub users expect / to do this.

What

Slash focuses the search box

Pressing / on an API page focuses the sidebar search box and selects its text, without typing the slash. The key is ignored inside text fields, with Ctrl, Meta or Alt held, and on screens narrower than 768px, where the sidebar is off-canvas. Shift is allowed because some keyboard layouts need it to type /. The logic lives in the new useSlashToFocus hook.

Placeholder names the shortcut

The API placeholder changes from Find in all APIs to Press ❲/❳ to find API, and the input gets aria-keyshortcuts="/" so assistive technology can announce the shortcut. Other uses of the component keep their placeholder and get no shortcut. The API Explorer page in docs/ names the box by its new placeholder and describes the shortcut.

Escape leaves the box

Esc already cleared the box and closed the results. On API pages it now also drops focus, as on GitHub. The blur waits for the re-render, so one Esc logs one navigation_search_closed event instead of two.

Verify

cd src/Elastic.Documentation.Site
npx jest Assets/web-components/NavigationSearch

Check on the preview

Out of scope: Ctrl+K is untouched. The handler that sent it to this box was removed in #4411, so the report in the issue came from an older build. Whether API pages should mount the header search is a separate question.

🤖 Generated with Claude Code

Pressing `/` outside a text field now focuses the sidebar search box on API pages, and `Esc` clears it and drops focus, as on GitHub. The placeholder reads `Press ❲/❳ to search API`. The shortcut applies only to `type="api"` on screens at least 768px wide.

This addresses [elastic/docs-eng-team#1096](elastic/docs-eng-team#1096). Its Ctrl+K complaint came from a build older than [#4411](#4411), which already removed that handler.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@technige
technige requested a review from a team as a code owner October 19, 2026 13:02
@technige
technige requested a review from akira28 October 19, 2026 13:02
The box has gone by names such as "Jump to page" and "Find in docs" so it is not confused with the site search. The placeholder now reads `Press ❲/❳ to find API`, and the docs call the box a finder. This follows review feedback on [#4511](#4511).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

Docs preview (local build)

Handbook preview: https://docs-v3-preview.elastic.dev/elastic/docs-builder/pull/4511/

Sample changed pages:

@technige
technige merged commit 2fcd852 into main Oct 19, 2026
32 checks passed
@technige
technige deleted the api-explorer-slash-focus-search branch October 19, 2026 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants