Signature
Expanding search
An icon that grows into a search field.
Docs search
An icon that grows into a search field. Click it (or press ⌘K / Ctrl K), type “d” to see results, then press Esc to fold it back.
Components
When to use
- Toolbars and headers where search is secondary and space is tight.
- When you want the field to take over the row only while it is in use.
- If search is the main task of the page, show a normal
Inputwith a search icon instead.
API
ExpandingSearch
| Prop | Type | Default | Description |
|---|---|---|---|
| value / defaultValue / onValueChange | string | — | The query, controlled or uncontrolled. |
| open / defaultOpen / onOpenChange | boolean | false | Expanded state, controlled or uncontrolled. |
| placeholder | string | 'Search' | Input placeholder. |
| label | string | 'Search' | Accessible name of the button and the field. |
| width | number | string | 280 | Expanded width (px or any CSS length). Never wider than the viewport minus 32px. |
| size | 'sm' | 'md' | 'lg' | 'md' | Height 32 / 36 / 44px. |
| shortcut | boolean | false | Press ⌘K (Ctrl K elsewhere) to expand and focus. Shows a hint while empty. |
| onSubmit | (value: string) => void | — | Enter pressed in the field. |
| results | ReactNode | — | Panel under the field while it is open and has a query. |
The results panel is positioned absolutely under the field, so keep the component out of ancestors with overflow: hidden.
Keyboard
| Key | Action |
|---|---|
| Enter / Space | On the icon: expands and focuses the field. |
| ⌘K / Ctrl K | With shortcut: expands and focuses from anywhere. |
| Enter | In the field: onSubmit. |
| Esc | Clears the query, collapses and returns focus to the icon. |
Accessibility
- The wrapper is a search landmark. The icon button has an accessible name and aria-expanded.
- The input is hidden from the tab order and the accessibility tree until the field is open, and focus moves into it when it opens.
- It folds back on blur only when empty, so a typed query is never lost; Tab out with text and it stays open.
- The input is type="search" with the browser’s own clear control replaced by a consistent Clear button.
Motion
- Width: a CSS transition on
--ui-spring-smooth(540ms, never overshoots) between the square icon button (36px) and the expanded width. - The input fades in 90ms after the field starts to grow, and stays mounted until the fold-back has finished so it never pops out.
- The results panel enters with the soft rise (380ms, 4px, blur clearing) and leaves faster (160ms).
- Reduced motion: the field opens and closes instantly; focus and results still behave the same.