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.
- 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.
- 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. - All changes →
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.jsonThe 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
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.
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
| Prop | Type | Default |
|---|---|---|
layersWhat the field looks in, in order: | GlassSearchLayer[] | — |
layers[].itemsResults known up front. Typing ranks them. | { value: string; label: string; description?: string; icon?: ReactNode; keywords?: string[]; disabled?: boolean }[] | — |
layers[].searchResults that take a while. Aborted when the text changes; what it resolves with is ranked, not filtered again. | (query: string, signal: AbortSignal) => Promise<GlassSearchItem[]> | — |
labelThe field's accessible name. | string | — |
placeholderShown while the field is empty. One too long for the field flows through it without end, as a marquee does. | string | — |
onActionCalled 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 | — |
onQueryChangeCalled with the text as it changes. | (query: string) => void | — |
defaultLayerThe layer the field looks in alone at first. | string | null | null |
onLayerChangeCalled when one layer is chosen or let go. | (layer: string | null) => void | — |
layersAfterHow long the empty field waits, under focus or the pointer, before its layers bud off (ms). | number | 2000 |
arrivePlay 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. | boolean | false |
emptyShown when nothing matches. Write it in the page's language. | ReactNode | 'No results' |
limitThe most results listed at once. | number | 50 |
materialClear glass frosts and bends what is behind; tinted takes the colour of your own | 'clear' | 'tinted' | 'clear' |
tintClear glass: how much tint covers the backdrop (0–1). | number | 0.74 |
blurClear glass: how much the backdrop is frosted, in px. | number | 3.5 |
classNameSizes the field; it is 20rem wide by default and always 48px tall at rest. | string | — |
Accessibility
- A
comboboxtext field that controls alistbox(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.