Skip to content

Components

SearchNew

A refractive glass search field that looks in several layers at once — apps, files, people — and opens into its ranked results, with its layers budding off the field as droplets.

Markdown
Latest changeNewv2.1.0Search: type once and it looks through apps, files, people or any layers you give it, ranks what it finds and completes the text with the best match. Rest on the empty field and the layers bud off it as droplets; press one to search that layer alone.
  1. v2.1.0NewSearch: type once and it looks through apps, files, people or any layers you give it, ranks what it finds and completes the text with the best match. Rest on the empty field and the layers bud off it as droplets; press one to search that layer alone.
  2. v2.1.0NewLayers can answer later: search(query, signal) results join the list when they arrive, and the request is cancelled as soon as the text changes.
  3. All changes →
glass-search-basic.tsx

Nothing opened yet

Use it for

  • A command or launcher field that finds things of several kinds at once: apps, documents, people, settings.
  • Results that come from a server, alongside ones you already have, with the slow ones joining as they arrive.

Not for

  • Picking one value for a form from a short, fixed list: use Select.
  • A handful of actions on a button, with nothing to type: use Menu.

Installation

npm install @vitrumui/react
Peer: React 19

The listbox, highlight, keyboard, announcements and ARIA come from UI SDK (@ui-sdk/core and @ui-sdk/react). Searching and ranking happen in the component.

Usage

app.tsx
import { LayoutGrid, Users } from 'lucide-react'
import { GlassSearch } from '@vitrumui/react/search'

<GlassSearch
  label="Search apps and people"
  placeholder="Search apps and people"
  layers={[
    {
      value: 'apps',
      label: 'Apps',
      icon: <LayoutGrid />,
      items: [
        { value: 'calendar', label: 'Calendar' },
        { value: 'maps', label: 'Maps', keywords: ['directions'] },
      ],
    },
    {
      value: 'people',
      label: 'People',
      icon: <Users />,
      items: [{ value: 'ada', label: 'Ada Moreno', description: 'Product design' }],
    },
  ]}
  onAction={(item, layer) => open(layer.value, item.value)}
/>

Each layer has a value, a label and an icon. Typing ranks every layer's items together; a result's own icon replaces its layer's. onAction runs on Enter or a press, and the field empties once it has run.

Examples

A static layer and an async one
glass-search-layers.tsx

Give a layer search(query, signal) instead of items and it answers when its promise settles. The signal aborts as soon as the text changes, so stop the request there. Its results are ranked with the rest but not filtered again.

Return a promise from onAction and the chosen result stays pending until it settles. If it rejects, the text stays so the visitor can try again.

API reference

PropTypeDefault
layers

Where to look: { value, label, icon, items?, search? }. The first four become droplets when they fit; every layer that answers shows as a chip.

GlassSearchLayer[]—
label / placeholder

The field's accessible name, and the hint shown while it is empty. A hint too long for the field scrolls through it.

string / string—
onAction

Runs when a result is chosen. Return a promise to keep the result pending until it settles.

(item, layer) => unknown—
onQueryChange

Called with the text on every change.

(query: string) => void—
defaultLayer / onLayerChange

The layer to search alone at first, and a callback when the visitor picks or releases one.

string | null / (layer: string | null) => voidnull
layersAfter

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

number2000
arrive

Play an arrival when the field mounts: it comes in a little large, out of a blur. For a field opened by a shortcut or in a dialog.

booleanfalse
empty / limit

What shows when nothing matches, and the most results listed at once.

ReactNode / number'No results' / 50
material / tint / blur

The glass: clear glass frosts and bends what is behind it. Inside a VitrumProvider, tint and blur follow the theme unless you set them.

'clear' | 'tinted' / number / number'clear' / 0.74 / 3.5
className / ref / …props

Size the field with className (w-full max-w-xl); ref and other attributes go to its root.

string / Ref<HTMLDivElement> / div attributes—

Keyboard and accessibility

  • The field is a combobox that controls a listbox. aria-expanded is true only while results are showing.
  • Up and Down move the highlight; Enter runs the highlighted result. Tab, or Right Arrow at the end of the text, takes the suggested completion.
  • Escape empties the field; pressed again, it releases the chosen layer. Backspace in an empty field releases it too.
  • Droplets and chips are buttons named by their layer. While the droplets are melted into the field they leave the tab order.
  • Matching ignores case and accents, so “sukru” finds “Şükrü”. The number of results is announced once typing pauses.
  • With reduced motion everything appears at once. Without WebGL2 it is a frosted field with round buttons at its end.