Skip to content
Search topics

Search panels that close on Tab and drop keyboard focus

The search panel closes as soon as its field loses focus, ignores Escape, and hides the control that had focus.

SC 2.1.1ASC 2.4.3ASC 4.1.2A Markdown for agents
Broken Try it
Closed, and focus is lost.
The accessibility problem illustrated.
01

The problem

Keyboard users cannot reach the search results, cannot close the panel with Escape, and lose their place when it closes.

02

Try it

Open Search, type, then press Tab to reach a result.

Can you reach both lamps and the close button? Try Escape too, and watch where focus ends up.

Broken Can you fix this?

Focus: –

A recreated demo. The broken version is intentionally inaccessible.

03

The fix

Close the panel only when the user asks or has left the whole component, and put focus back on its button when they ask.

  1. 1Moving focus inside the panel never closes it.
  2. 2Escape and a named close button close it and return focus to its button.
  3. 3The opening button says whether the panel is open.
Before A panel that closes whenever the field loses focus
<button type="button" id="search-trigger">Search</button><div id="search-panel" hidden>  <label for="search-input">Search products</label>  <input id="search-input" type="search">  <ul>    <li><a href="/lamps/arc">Arc floor lamp</a></li>    <li><a href="/lamps/dome">Dome table lamp</a></li>  </ul>  <button type="button" id="search-close">Close</button></div><button type="button">Cart</button>
After

A disclosure that closes when asked

<div id="search">  <button type="button" id="search-trigger" aria-expanded="false" aria-controls="search-panel">Search</button>  <div id="search-panel" tabindex="-1" hidden>    <label for="search-input">Search products</label>    <input id="search-input" type="search">    <ul>      <li><a href="/lamps/arc">Arc floor lamp</a></li>      <li><a href="/lamps/dome">Dome table lamp</a></li>    </ul>    <button type="button" id="search-close">Close search</button>  </div></div><button type="button">Cart</button>

04

Verify the fix

5 checks, no mouse.

Test with: Keyboard, Screen reader

0 of 5 checked

Record the OS, browser and assistive-technology versions, the build, the date, and the actual result of each step. Repeat after the shared header or search component changes.

Limits

This is a starting pattern for a non-modal search panel, not for comboboxes, menus or dialogs. The snippets omit fetching and announcing results. Test the complete journey, including your real results list, with your target assistive technology.

This is a recreated teaching example, not a finding about a named client. The code is a starting pattern: test it in your own product. No completed assistive-technology test is claimed here.

Keep this fixed as your code changes.

Turn guides like this into rules your coding agents and CI follow, then have the result retested with a keyboard and screen readers.

How retests work