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.
input.addEventListener('blur', close) The problem
Keyboard users cannot reach the search results, cannot close the panel with Escape, and lose their place when it closes, and screen reader users aren't told whether the panel is open
A shop's header has a Search button. Activate it and a panel opens below with a search field, a short list of results and a Close button. Type "lamp" and press Tab to reach the first result: the panel disappears, and focus with it. Open it again and press Escape: nothing happens. The next Tab starts from somewhere the user didn't choose. With a screen reader, the button is read as "Search, button" before and after it opens the panel, with no word of whether anything opened.
A blur handler on the field closes the panel 200 milliseconds after the field loses focus, including when focus moves to a result inside the same panel.
Success criterion 2.1.1 Keyboard asks that everything the mouse can do, the keyboard can do. A mouse click on a result lands inside the delay, but Tab moves focus first and the panel closes under it, so the results and the Close button can't be used from the keyboard. Nothing listens for Escape either.
Success criterion 2.4.3 Focus Order asks that focus moves in an order that keeps the task intact. The result is hidden while it has focus, and hiding an element doesn't move focus anywhere useful, so the browser drops it to the page. Nothing puts it back on the Search button, so a keyboard user can't see where they are, and the next Tab starts from a point they didn't choose.
Success criterion 4.1.2 Name, Role, Value asks that a control exposes its current state. The Search button opens and closes the panel, but it has no aria-expanded, so a screen reader reads it the same way whether the panel is open or closed, and a screen reader user can't tell whether pressing it did anything.
The delay lets a mouse click on a result land before the panel closes, so mouse users never meet the bug, and it can go unnoticed for a long time.
2 of 10 groups affected
- No vision (affected)
- Low vision (not affected)
- Colour vision (not affected)
- No hearing (not affected)
- Hard of hearing (not affected)
- No speech (not affected)
- Motor (affected)
- Reach, strength (not affected)
- Cognitive (not affected)
- Seizures (not affected)
- Limited manipulation Keyboard and switch users can type a query but can't pick a result. When the panel closes, they have to find their place again from the top of the page.
- Without vision Screen reader users can type a query but can't reach the results, and have to find their place again when the panel closes.
The markup is a named button, a labelled field and ordinary links, so a static scan finds nothing to report. The failure only appears when focus moves after the panel is open. Closing on blur is a common suggestion for "close the dropdown when the user clicks away", and AI coding tools reproduce it without checking where focus is going.
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. Does Search say whether the panel is open?
Broken Can you fix this?
Focus: –
The fix
Close the panel when asked, and return focus to its button
<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>What is wrong5 points
- Keyboard users can't pick a result: Tab from the field closes the panel before the result can be used.
- The close button can't be reached from the keyboard at all: the panel closes before Tab gets that far.
- Escape doesn't close the panel: nothing listens for it.
- After it closes, a keyboard user can't tell where focus is: nothing returns it to Search.
- A screen reader user isn't told whether the panel opened: the button has no
aria-expanded.
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>How it is fixed5 steps
- Wrap the button and the panel in one
#search, with the panel right after the button in the markup. Tab then goes from the button to the field, the results, the close button and then Cart. - Give Search
aria-expandedandaria-controls, and updatearia-expandedas the panel opens and closes, so Search says whether its panel is open. - Close the panel on Escape, from Close search and from Search, and put focus back on Search.
- Replace the field's
blurtimer with afocusoutlistener on the whole component. Moving focus inside it keeps the panel open, and Tab or Shift + Tab out of it closes the panel without moving focus anywhere else. - Put
tabindex="-1"on the panel, so a click on its blank space keeps focus inside and doesn't close it.
This fixes the Before and passes 2.1.1, 2.4.3 and 4.1.2.
Why this fix: Change the page only when people ask
Both pass. The scripted disclosure works in every browser, keeps the panel in the page's own layout, and can close when focus leaves the component, but every piece of it is your code to maintain. The popover needs no script and gets Escape, the expanded state and focus return from the browser. It sits in the top layer, so you position it yourself (with CSS anchor positioning or a few lines of script), and it stays open when the user tabs away. Choose the popover when the browsers you support all have it and an open panel left behind is acceptable. Choose the disclosure when the panel must close on focus-out or lives inside a layout the top layer would break.
Closing on focus-out is a design choice, not a requirement. A panel that stays open after the user tabs away is not a keyboard trap, because focus did leave. What fails is closing while focus is still inside, or pulling focus back in after it has left. If you close on focus-out, check relatedTarget against the whole component, never just the field.
Return focus to the button only when the user closes the panel on purpose, with Escape or the close button. When they Tab away or click elsewhere, leave focus where they put it. In browsers that clear a type="search" field on Escape, you may let a first Escape clear the text and a second close the panel; test both presses.
This is a non-modal panel. Don't add a focus trap, aria-modal or an inert page; those belong to the modal-focus-management guide. If focus stays in the field while the arrow keys move through suggestions, the component is a combobox and follows that pattern instead, with aria-activedescendant and announced results: see autocomplete fields with silent, mouse-only suggestions. Name the close control in words, or see icon-buttons for an icon-only ×.
Verify the fix
5 checks, no mouse.
Test with: Keyboard, Screen reader
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.
How screen readers handle aria-expanded
Limits
This is a starting pattern for a non-modal search panel, not for comboboxes, menus or dialogs. A chat panel that opens over the page has the same closing to get right, and replies to announce as well: see chat widgets that never announce their messages. A panel placed at the end of the page, away from its button, is a different failure of 2.4.3: see floating buttons and panels that keyboard focus reaches last. 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.
EaseWeb service
Fixed it? Keep it from coming back.
I turn guides like this one into rules your coding agents follow and checks your CI runs. Then I retest by hand with a keyboard and screen readers, periodically.