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.
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.
- 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.
- 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. - All changes →
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/reactThe 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
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
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
| Prop | Type | Default |
|---|---|---|
layersWhere to look: | GlassSearchLayer[] | — |
label / placeholderThe field's accessible name, and the hint shown while it is empty. A hint too long for the field scrolls through it. | string / string | — |
onActionRuns when a result is chosen. Return a promise to keep the result pending until it settles. | (item, layer) => unknown | — |
onQueryChangeCalled with the text on every change. | (query: string) => void | — |
defaultLayer / onLayerChangeThe layer to search alone at first, and a callback when the visitor picks or releases one. | string | null / (layer: string | null) => void | null |
layersAfterHow long the empty field waits under focus or the pointer before its layers bud off, in ms. | number | 2000 |
arrivePlay 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. | boolean | false |
empty / limitWhat shows when nothing matches, and the most results listed at once. | ReactNode / number | 'No results' / 50 |
material / tint / blurThe glass: clear glass frosts and bends what is behind it. Inside a VitrumProvider, | 'clear' | 'tinted' / number / number | 'clear' / 0.74 / 3.5 |
className / ref / …propsSize the field with | string / Ref<HTMLDivElement> / div attributes | — |
Keyboard and accessibility
- The field is a combobox that controls a listbox.
aria-expandedis 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.