Skip to content

Components

Search

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 change Fixed v3.0.18 The field no longer draws a blue ring around itself. The ring 3.0.16 added for the keyboard showed on every press as well, since a text field counts as focused by the keyboard however it was reached; the caret says where focus is, as before.
  1. v3.0.18 Fixed The field no longer draws a blue ring around itself. The ring 3.0.16 added for the keyboard showed on every press as well, since a text field counts as focused by the keyboard however it was reached; the caret says where focus is, as before.
  2. v3.0.16 Fixed The field shows a focus ring when it is reached by the keyboard. Until now only the caret said where focus was.
  3. v3.0.9 Improved Once open, the field takes a new count of results at once: typing no longer makes it glide under every key. The height is written on the engine's frame, so the glass is never a frame behind it. The results no longer scroll the page once they reach their end.
  4. v2.2.1 Improved Search's rim is a button's: the faint white line it drew just inside its edge, under the rim light, is gone, so the light on its rim is as thin as on a Button. The dark hairline on its very edge stays.
  5. v2.1.2 Fixed The field told screen readers its results were open at all times (aria-expanded="true"), also when it was empty or after Escape had emptied it. It now follows the glass: true while the results show, false when the field has closed over them.
  6. v2.1.1 Improved The 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.
  7. All changes→
glass-search-basic.svelte

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-svelte@latest add https://liquidglass.pulse.city/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()
    },
  },
]

Speed: the preview above has a Default / Quick switch. Quick plays Emil Kowalski's timings; the default is the speed the glass was made with. Set it on one component with tempo, or for the whole page once with setGlassTempo('quick'); the prop wins over the page. Nothing extra to install.

API reference

PropTypeDefault
tempo

On GlassSearch: quick: it opens in 250 ms and closes in 200 (Emil Kowalski's timings), the same motion played faster. Left out: the page's tempo (setGlassTempo), else default, the speed it was made with.

'default' | 'quick''default'
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.

Liquid Glass Svelte is open source and MIT licensed. If it saves you time, you can support the project.