---
title: "Expanding Search"
description: "A round search button that grows into a search field when you press it. It closes again when the field is empty and you move away."
url: https://gelatinui.com/components/expanding-search
markdown_url: https://gelatinui.com/components/expanding-search.md
access: pro
install: "npx shadcn@latest add @gelatin-ui-pro/expanding-search"
version: "2026-11-09"
index: https://gelatinui.com/llms.txt
docs_index: https://gelatinui.com/docs/llms.txt
---

# Expanding Search

> A round search button that grows into a search field when you press it. It closes again when the field is empty and you move away.

Page: https://gelatinui.com/components/expanding-search

## When to use it

Best for: A search that must take little room until people need it, in a header or an app bar.

- Use it when the header has no room for a full field at rest.
- Use `align="end"` for a search at the end of a header: the field grows toward the start.
- Use `shortcut` to open it with a key, such as `/`.

## When not to use it

- For a search that is the main task of the page, use a [Search Field](https://gelatinui.com/components/search-field.md).
- For a search of commands and pages in a popup, use a [Command](https://gelatinui.com/components/command.md).

## Notes for agents

- Give it an `aria-label`. The round button takes the same name.
- The root keeps the open width in the layout (default `w-60`). Set the width with `className`.
- It stays open while it holds text. Escape on an empty field closes it and puts the focus on the button.
- `open`, `defaultOpen`, and `onOpenChange` hold the open state. `value` and `onValueChange` hold the text.
- All Search Field props pass through: `size`, `busy`, `shortcut`, `placeholder`.

## Anatomy

```text
ExpandingSearch
```

## API reference

### ExpandingSearch

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `value` | `string` |  | The text, when the parent owns it. |
| `defaultValue` | `string` | "" | The first text, when the field owns it. Default "". |
| `onValueChange` | `function` |  | Each change of the text, at once (each key, a clear). |
| `onSearch` | `function` |  | Run the search: on Enter, on a clear (with ""), and after `debounce` ms of no typing. |
| `onClear` | `function` |  | The text was cleared (the clear button, or Escape with text). |
| `debounce` | `number` |  | Ms of no typing before `onSearch` runs. `undefined` (the default): typing does not search, only Enter and a clear do. `0`: each change searches. |
| `shortcut` | `false \| SearchFieldShortcut` |  | The key that focuses and selects the field from anywhere. Default `false` (none). |
| `className` | `string` |  | Classes of the frame (the InputGroup), for its width. The classes of the root. Its width is the open width (default `w-60 max-w-full`). |
| `busy` | `boolean` |  | The field waits for results: the spinner takes the place of the search icon, and the input is `aria-busy`. |
| `size` | `"default" \| "lg" \| "sm" \| "xs"` | "default" |  |
| `variant` | `"dashed" \| "default"` |  |  |
| `open` | `boolean` |  | The field is open (controlled). It also stays open while it holds text. |
| `defaultOpen` | `boolean` | false | The field starts open (uncontrolled). Default `false`. |
| `onOpenChange` | `function` |  | The field opened or closed. |
| `align` | `"end" \| "start"` | "start" | The side that stays put while the field grows: `start` (default) or `end`, for a header. |
| `labels` | `Partial` |  | The words: `trigger`, and the Search Field words `clear` and `loading`. Keep it stable. |

## Styling

| Part | Slot | States | CSS variables | Tokens |
| --- | --- | --- | --- | --- |
| ExpandingSearch | `expanding-search` | `data-input-group-control`, `data-stage-active` |  | `hit-area`, `motion-timing` |

## Usage

A search button that grows into a field. Read the text with `onValueChange`.

```tsx title="header-search.tsx"
import { ExpandingSearch } from "@/components/ui/pro/expanding-search";

export function HeaderSearch() {
  return (
    <ExpandingSearch
      aria-label="Search the shop"
      placeholder="Search products"
      onValueChange={(query) => console.log(query)}
    />
  );
}
```

## Compose

Rules:

- Compose the parts (`compose-parts`): Build each item from its named parts as children, and pass your text and icons in as parts.
- Every state is designed (`every-state`): Give each view of data its loading, empty, and error states: a skeleton in the final layout, an `Empty` with an illustration and one next action, and an error that says what failed and how to retry.

## Add it

```bash
npx shadcn@latest add @gelatin-ui-pro/expanding-search
```

It adds 26 registry items: 23 files, 4152 lines, and the npm packages `@base-ui/react`, `@mantine/hooks`, `@phosphor-icons/react`, `@tanstack/react-hotkeys`, `clsx`, `motion`, `tailwind-merge`, `tailwind-variants`.

## Built on

- [Search Field](https://gelatinui.com/components/search-field.md)

## For AI agents

- Every item, one file: https://gelatinui.com/llms.txt
- MCP server (`search_items`, `get_item`, `get_install_plan`): https://gelatinui.com/mcp

## Related

- [Search Field](https://gelatinui.com/components/search-field.md)
- [Input Group](https://gelatinui.com/components/input-group.md)
- [Command](https://gelatinui.com/components/command.md)

## Keyboard

| Keys | Action |
| --- | --- |
| Enter, Space | On the round button: opens the field and moves the focus into it. |
| Escape | Clears the text. On an empty field: closes it and puts the focus on the button. |
| / | Opens the field when `shortcut` is `/`. |

## Motion

| Part | Motion |
| --- | --- |
| Open and close | island · the frame grows from a circle to the full width, and the icon stays in place |
| Text | fade · the text and the placeholder fade in and out |
| Press | press · the button scales to 0.94 |
