Morph Search

Expanding Search Bar for React

A search button that stretches into a search field, with results unfolding underneath as one shape, and shrinks back into the button when it closes.

  • Search
  • Command Menu
  • Motion

Uses motion, clsx, tailwind-merge

Open in ChatGPTOpen in Claude
variant
speed1.00×
stagger0.022s
shape
<MorphSearch />

The demo follows as you drag.

Take this demo to your coding agent.
Add this moment from KeyframeUI to our project and adapt it to our content.

Morph Search: A search button that stretches into a search field, with results unfolding underneath as one shape, and shrinks back into the button when it closes.
This demo, Nav Bar: A search button in a site header. It grows into a field with popular pages underneath; pick one to go there.

1. Install it:
   npx shadcn@latest add @keyframeui/morph-search-demo
   (If the CLI can't find @keyframeui, use https://keyframeui.com/r/morph-search-demo.json instead.)
   It adds the demo, components/morph-search-demo.tsx, and the component, components/ui/morph-search.tsx.

2. Make it ours: our copy, data, images and colors. Keep the structure the motion depends on. If we only need the effect, use <MorphSearch> on its own.

3. These props set its feel. Change them before you change the file:
   - variant (default "inline"): `inline` grows from the trigger in place, for a nav bar. `palette` travels to the middle of the screen over a dimmed page, for a command menu.
   - speed (default 1): How fast every morph, fold and fade plays, as a multiple of the default pace. `2` is twice as fast.
   - stagger (default 0.022): Seconds between rows as the results ripple in.
   - shape (default "round"): The corners. `round`: a pill trigger and soft corners. `sharp`: square everywhere (trigger, panel, rows, highlight, keys) for square-cornered sites; the motion, shadow and colors stay the same.

4. Don't change, in components/ui/morph-search.tsx:
   - The shape's position, size and corners all derive from the `progress` and `panel` motion values through `useTransform`, so morphing, unfolding and resizing never re-render.
   - Closing folds the results, then shrinks the field into the trigger, and grabbing it on the way back reopens it from there. `finish` shows the trigger, closes the layer and returns focus in one task, so no frame shows both or neither.
   - Reduced motion skips the morph: the shape starts at its open size and only fades, through `veil`. A trigger scrolled off screen fades it in place too, instead of morphing from it.
   - The highlight is drawn from its motion values onto a plain element, not bound to a motion element, which StrictMode's remount would reset.
   - Focus stays in the input: it's a `combobox` with `aria-activedescendant`, and a mousedown anywhere but the input and buttons is prevented.
   Its timing is all in the TIMING block at the top of that file.

Docs: https://keyframeui.com/components/morph-search.md

Installation

Add the component on its own with the CLI, or copy the file in by hand.

The CLI writes components/ui/morph-search.tsx and installs motion, clsx and tailwind-merge. It needs the @keyframeui registry in components.json; add it once per project.

npx shadcn@latest add @keyframeui/morph-search

Examples

Finished sections built with Morph Search. Each one installs whole, with the component included.

Command Menu

An app's command menu. The trigger travels to the middle of the screen, with grouped commands and their shortcuts. Opens with ⌘K.

Take this demo to your coding agent.
Add this moment from KeyframeUI to our project and adapt it to our content.

Morph Search: A search button that stretches into a search field, with results unfolding underneath as one shape, and shrinks back into the button when it closes.
This demo, Command Menu: An app's command menu. The trigger travels to the middle of the screen, with grouped commands and their shortcuts. Opens with ⌘K.

1. Install it:
   npx shadcn@latest add @keyframeui/morph-search-command-demo
   (If the CLI can't find @keyframeui, use https://keyframeui.com/r/morph-search-command-demo.json instead.)
   It adds the demo, components/morph-search-command-demo.tsx, and the component, components/ui/morph-search.tsx.

2. Make it ours: our copy, data, images and colors. Keep the structure the motion depends on. If we only need the effect, use <MorphSearch> on its own.

3. These props set its feel. Change them before you change the file:
   - variant (default "inline"): `inline` grows from the trigger in place, for a nav bar. `palette` travels to the middle of the screen over a dimmed page, for a command menu.
   - speed (default 1): How fast every morph, fold and fade plays, as a multiple of the default pace. `2` is twice as fast.
   - stagger (default 0.022): Seconds between rows as the results ripple in.
   - shape (default "round"): The corners. `round`: a pill trigger and soft corners. `sharp`: square everywhere (trigger, panel, rows, highlight, keys) for square-cornered sites; the motion, shadow and colors stay the same.

4. Don't change, in components/ui/morph-search.tsx:
   - The shape's position, size and corners all derive from the `progress` and `panel` motion values through `useTransform`, so morphing, unfolding and resizing never re-render.
   - Closing folds the results, then shrinks the field into the trigger, and grabbing it on the way back reopens it from there. `finish` shows the trigger, closes the layer and returns focus in one task, so no frame shows both or neither.
   - Reduced motion skips the morph: the shape starts at its open size and only fades, through `veil`. A trigger scrolled off screen fades it in place too, instead of morphing from it.
   - The highlight is drawn from its motion values onto a plain element, not bound to a motion element, which StrictMode's remount would reset.
   - Focus stays in the input: it's a `combobox` with `aria-activedescendant`, and a mousedown anywhere but the input and buttons is prevented.
   Its timing is all in the TIMING block at the top of that file.

Docs: https://keyframeui.com/components/morph-search.md

Docs Search

A docs header with a fake search field that becomes the real one. Press / to open it from anywhere.

Take this demo to your coding agent.
Add this moment from KeyframeUI to our project and adapt it to our content.

Morph Search: A search button that stretches into a search field, with results unfolding underneath as one shape, and shrinks back into the button when it closes.
This demo, Docs Search: A docs header with a fake search field that becomes the real one. Press / to open it from anywhere.

1. Install it:
   npx shadcn@latest add @keyframeui/morph-search-docs-demo
   (If the CLI can't find @keyframeui, use https://keyframeui.com/r/morph-search-docs-demo.json instead.)
   It adds the demo, components/morph-search-docs-demo.tsx, and the component, components/ui/morph-search.tsx.

2. Make it ours: our copy, data, images and colors. Keep the structure the motion depends on. If we only need the effect, use <MorphSearch> on its own.

3. These props set its feel. Change them before you change the file:
   - variant (default "inline"): `inline` grows from the trigger in place, for a nav bar. `palette` travels to the middle of the screen over a dimmed page, for a command menu.
   - speed (default 1): How fast every morph, fold and fade plays, as a multiple of the default pace. `2` is twice as fast.
   - stagger (default 0.022): Seconds between rows as the results ripple in.
   - shape (default "round"): The corners. `round`: a pill trigger and soft corners. `sharp`: square everywhere (trigger, panel, rows, highlight, keys) for square-cornered sites; the motion, shadow and colors stay the same.

4. Don't change, in components/ui/morph-search.tsx:
   - The shape's position, size and corners all derive from the `progress` and `panel` motion values through `useTransform`, so morphing, unfolding and resizing never re-render.
   - Closing folds the results, then shrinks the field into the trigger, and grabbing it on the way back reopens it from there. `finish` shows the trigger, closes the layer and returns focus in one task, so no frame shows both or neither.
   - Reduced motion skips the morph: the shape starts at its open size and only fades, through `veil`. A trigger scrolled off screen fades it in place too, instead of morphing from it.
   - The highlight is drawn from its motion values onto a plain element, not bound to a motion element, which StrictMode's remount would reset.
   - Focus stays in the input: it's a `combobox` with `aria-activedescendant`, and a mousedown anywhere but the input and buttons is prevented.
   Its timing is all in the TIMING block at the top of that file.

Docs: https://keyframeui.com/components/morph-search.md

Props

items Required

TypeMorphSearchItem[]

What to search. Each item has an id and label, and optionally a description, group, icon, shortcut (keys shown on the right), keywords and href (the row becomes a link, so ⌘-click opens it in a new tab).

onSelect

Type(item: MorphSearchItem) => void

Called when a result is picked with Enter or a click. The search closes after.

variant

Type"inline" | "palette"Default"inline"

inline grows from the trigger in place, for a nav bar. palette travels to the middle of the screen over a dimmed page, for a command menu.

speed

TypenumberDefault1

How fast every morph, fold and fade plays, as a multiple of the default pace. 2 is twice as fast.

stagger

TypenumberDefault0.022

Seconds between rows as the results ripple in.

suggestions

TypeMorphSearchItem[]

Shown before anything is typed. Defaults to items.

placeholder

TypestringDefault"Search…"

Placeholder for the field. Also its accessible name.

hotkey

Typestring

"k" opens and closes it with ⌘K (Ctrl+K elsewhere). "/" opens it with a bare slash.

width

TypenumberDefault360 (inline), 560 (palette)

Width of the open field, in pixels. Never wider than the screen.

align

Type"start" | "end"

Inline only: which edge of the trigger the field grows from. Defaults to the side with more room.

filter

Type(item: MorphSearchItem, query: string) => number

Scores an item against the query. 0 hides it; higher ranks first. The default matches every word and ranks labels that start with the query first.

onQueryChange

Type(query: string) => void

Called as the query changes. For server results, update items from here and pass a filter that returns 1.

emptyMessage

Type(query: string) => React.ReactNode

Shown when nothing matches.

footer

Typeboolean | ((active: MorphSearchItem | null) => React.ReactNode)Defaulttrue for palette

Keyboard hints under the results. A function replaces them with your own bar, given the highlighted item (an action on it, a count).

children

TypeReact.ReactNode

Custom trigger content, such as a fake search field. Use MorphSearchIcon for its magnifier so it slides into the open field.

className

Typestring

Classes for the trigger button. Its look and corner radius carry into the morph.

surfaceClassName

Typestring

Classes for the open surface's background. Defaults to bg-background.

shape

Type"round" | "sharp"Default"round"

The corners. round: a pill trigger and soft corners. sharp: square everywhere (trigger, panel, rows, highlight, keys) for square-cornered sites; the motion, shadow and colors stay the same.

renderItem

Type(item: MorphSearchItem, state: { active: boolean; query: string }) => React.ReactNode

Draws a row's content instead of the icon, label and description: a thumbnail, a second line, why it matched.

notice

TypeReact.ReactNode

Shown above the results, such as a note on how the query was read.

afterResults

TypeReact.ReactNode

Shown after the results, inside the list: a way out when the matches are weak.

groupOrder

Typestring[]

Groups in this order. Without it, groups follow their best match.

onInputKeyDown

Type(event: React.KeyboardEvent<HTMLInputElement>, active: MorphSearchItem | null) => void

Runs first on a key in the field, with the highlighted item. Call preventDefault() to skip the built-in handling.

onOpenChange

Type(open: boolean) => void

Called as it opens and once it has closed: load results on open, pause the page behind.

handle

TypeReact.Ref<MorphSearchHandle>

Gets open() and close(), to open it from your own shortcut or button.