Skip to content

Components

SearchNew

A search field that looks in several layers at once. Left empty, it lets its layers bud off its end as droplets; typed in, they melt back and the field grows down into its results.

Latest changeImprovedv2.1.1The example looks in other content: the people are companions of the Prophet (Bilal ibn Rabah, Muadh ibn Jabal, Musab ibn Umayr, Umar ibn al-Khattab), the apps are Quran, Prayer times and Qibla next to Calendar, Maps and Notes, and the files and actions follow them.
  1. v2.1.1ImprovedThe example looks in other content: the people are companions of the Prophet (Bilal ibn Rabah, Muadh ibn Jabal, Musab ibn Umayr, Umar ibn al-Khattab), the apps are Quran, Prayer times and Qibla next to Calendar, Maps and Notes, and the files and actions follow them.
  2. v2.1.0NewSearch (GlassSearch): a search field that looks in several layers at once. Left empty under focus or the pointer, it pulls its end back and lets its layers out as a string of droplets that grow, spread and let go of each other; typed in, they melt back, the best match completes the text and the field grows down into its results, with the layers that answered as chips. A layer can answer later (search), and its results join the list when they arrive. Behaviour is UI SDK's Command.
  3. All changes →
glass-search-basic.tsx

Use it for

  • Finding one thing among several kinds of things from a single field: apps, files, people, actions.
  • A command palette that lives on the page instead of in a dialog.
  • Sources that answer at different speeds: each layer joins the list when it is ready.

Not for

  • Picking a value for a form: use Select.
  • A handful of known actions: use Menu or Dropdown Menu.
  • Filtering one list of one kind of thing: a plain input does it. The layers are the point here.

Installation

npx shadcn@latest add https://liquidglass.onemorethink.dev/r/search.json

The behaviour (the list, the highlight and arrow keys, Enter, the announcements, ARIA) comes from UI SDK's Command, so Search needs @ui-sdk/core and @ui-sdk/react. The install command adds them at the exact version this was built on: UI SDK is in beta and its API may still change.

Usage

app.tsx
import { GlassSearch } from '@/components/liquid-glass/glass-search'

<GlassSearch
  label="Search"
  placeholder="Search"
  className="w-full max-w-md"
  onAction={(item, layer) => open(layer.value, item.value)}
  layers={[
    {
      value: 'apps',
      label: 'Apps',
      icon: <LayoutGrid />,
      items: [
        { value: 'notes', label: 'Notes' },
        { value: 'quran', label: 'Quran' },
      ],
    },
    {
      value: 'people',
      label: 'People',
      icon: <Users />,
      items: [{ value: 'muadh', label: 'Muadh ibn Jabal', description: 'Teacher of Yemen' }],
    },
  ]}
/>

Left empty under focus or the pointer for two seconds, the field pulls its end back and its layers come out of it as one string of droplets: small at first, growing as they spread, the nearest pinching off where it belongs, then each of the others letting go of the next. Their icons ride with them and, in order, fade up, grow from their centre and clear out of a blur as they land. Type, and the droplets melt back in one quick motion, the best match completes what you typed, and the field grows down into its results; empty it and the glass shuts over them from below, softly, on a spring with some weight. It is one body of glass from start to end, shaded for the height it has at rest, with a hairline of dark on its very edge. Its face is frosted and takes only a little of the kit's light; its rim keeps the light, which leans towards the pointer as it moves around the field, and its shadow is Card's. The glass is clear, so it needs something behind it to bend.

Layers

A layer is a kind of thing to look in. Give it items when you have them up front: typing ranks them (the start of the label first, then the start of a word, then anywhere, then keywords), without case or accents. Give it search when the answer takes a while: it is called with what was typed and aborted when that changes, and what it resolves with joins the list when it arrives. Layers that answered line up as chips above the results. Press a droplet or a chip and the field looks in that layer alone; it shows in the field, and Backspace in the empty field lets it go. Up to four layers bud off as droplets, as many as leave the field at least 120px to type in; any others show only as chips.

layers.tsx
const layers: GlassSearchLayer[] = [
  // Known up front: ranked as you type.
  { value: 'apps', label: 'Apps', icon: <LayoutGrid />, items: apps },
  // Takes a while: joins the list when it resolves.
  {
    value: 'files',
    label: 'Files',
    icon: <Folder />,
    search: async (query, signal) => {
      const response = await fetch(`/api/files?q=${encodeURIComponent(query)}`, { signal })
      return response.json()
    },
  },
]

API reference

PropTypeDefault
layers

What the field looks in, in order: { value, label, icon, items?, search? }.

GlassSearchLayer[]—
layers[].items

Results known up front. Typing ranks them.

{ value: string; label: string; description?: string; icon?: ReactNode; keywords?: string[]; disabled?: boolean }[]—
layers[].search

Results that take a while. Aborted when the text changes; what it resolves with is ranked, not filtered again.

(query: string, signal: AbortSignal) => Promise<GlassSearchItem[]>—
label

The field's accessible name.

string—
placeholder

Shown while the field is empty. One too long for the field flows through it without end, as a marquee does.

string—
onAction

Called when a result is chosen (Enter or a press). Return a promise and the result stays pending until it settles; then the field empties.

(item, layer) => unknown—
onQueryChange

Called with the text as it changes.

(query: string) => void—
defaultLayer

The layer the field looks in alone at first. null = every layer.

string | nullnull
onLayerChange

Called when one layer is chosen or let go.

(layer: string | null) => void—
layersAfter

How long the empty field waits, under focus or the pointer, before its layers bud off (ms).

number2000
arrive

Play the field's arrival when it mounts: it comes in a little large, out of a blur. For a field that is summoned, in a dialog or on a shortcut.

booleanfalse
empty

Shown when nothing matches. Write it in the page's language.

ReactNode'No results'
limit

The most results listed at once.

number50
material

Clear glass frosts and bends what is behind; tinted takes the colour of your own bg-* class.

'clear' | 'tinted''clear'
tint

Clear glass: how much tint covers the backdrop (0–1).

number0.74
blur

Clear glass: how much the backdrop is frosted, in px.

number3.5
className

Sizes the field; it is 20rem wide by default and always 48px tall at rest.

string—

Accessibility

  • A combobox text field that controls a listbox (UI SDK's Command): focus stays in the field while the arrow keys move the highlight, and result counts are announced after typing pauses.
  • Enter runs the highlighted result. Tab or the right arrow at the end of the text takes the completion. Escape empties the field, then lets the chosen layer go; Backspace in the empty field does the same.
  • Droplets and chips are buttons named by their layer's label. The droplets leave the tab order while they are melted in.
  • With reduced motion the droplets and the results appear at once, with no budding or growth.
  • Without WebGL2 it is a plain frosted field with round buttons at its end.