Search
A search bar that opens a full-screen view on phones and a docked view on larger windows, and an app bar with search.
import { SearchBar, SearchAppBar } from '@windmorph/react';Keyboard
| Key | Action | Where |
|---|---|---|
| Tab or Shift + Tab | Moves focus between the icon buttons and the input. Focus alone does not expand the bar.On the bar | On the bar |
| Arrow Down | Expands the bar into the search view.On the bar | On the bar |
| Enter | Expands the bar into the search view, as a click does (Compose expands the bar as its field takes focus); the query is submitted from the view.On the bar | On the bar |
| Arrow Down | Moves focus from the input to the first focusable item in the results.In the search view | In the search view |
| Enter | Submits the query (onSubmit) and moves focus to the results, leaving the query visible.In the search view | In the search view |
| Escape | Collapses the search view.In the search view | In the search view |
- Typing into the collapsed input, or pressing it, also expands the bar.
- Moving between results with the arrow keys is up to the results themselves, such as a
List.
Screen reader
- Role
- The collapsed input is a
comboboxwhose popup is adialog(aria-haspopup="dialog"). The expanded view is a modaldialogwith its ownsearchboxinput.SearchAppBaris aheader. - Accessible name
- The input and the view are both named by the bar's
aria-labeloraria-labelledby, which the types require. The placeholder is not the name. The bar'saria-describedby,aria-detailsandaria-descriptiondescribe both inputs (before aninputProps['aria-describedby']). - States announced
- Expanded or collapsed (
aria-expandedon the collapsed input).
- While the view is open, the collapsed input is
inertandaria-hidden, so only one input is reachable. resultsAnnouncement("5 results") is read by a polite live region (role="status") inside the view when the view opens and whenever it changes, as M3 asks.
Focus
- The bar is in the Tab order where it sits. Keyboard focus in the input draws the 3px
secondaryfocus ring inside the pill; pointer presses show no ring. - When the view opens, focus moves to the view's input with the caret after the query. Focus stays inside the view while it is open, and returns as soon as it starts closing to what had it when the view opened: the bar, so pressing or typing on it while the view leaves opens it again, or, when a keyboard shortcut opened the view, the element that was focused then.
Touch target
- The bar is 56px tall, and the leading and trailing icon slots are 48 × 48px.
- The icon buttons inside are
standardIconButtons, which keep their own 48 × 48px touch target.
Motion
- The view grows out of the bar and shrinks back onto it on the M3 spatial springs, without overshooting the bar on the way back, and the docked results area resizes on a spring as the results change.
- Under reduced motion the docked field opens at its focused size at once, the results area resizes at once, and the dropdown only fades, without sliding.
- The full-screen view fades in and out over the window instead of growing from the bar.
What you need to do
- Name the bar with
aria-labeloraria-labelledby, matching the placeholder ("Search mail"). A bar inside aSearchAppBarstill needs its own name. - Pass
resultsAnnouncementwith the number of suggestions or results, so screen readers hear the change. - Give every icon-only button in
leadingIconandtrailingIconanaria-label, and give the full-screen view a back button that callscollapse. - Build suggestions and results from a
List, so they are announced as a list.