Select
A select whose list swells out of its button as one body of glass, holds on by a neck that stretches and snaps, and closes by the same motion played backwards.
Use it for
- Picking one option from a short list that should stay out of the way until asked for.
- A form field: the value is submitted under
name.
Not for
- Two to five options that fit on one line: use Tabs.
- An on/off setting: use Switch.
- Several of these on one screen: one stretching list is a moment, a form full of them is noise.
Installation
npm install @vitrumui/reactThe behaviour (keyboard, typeahead, focus, positioning, ARIA) comes from UI SDK, so Select 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. The rest of the kit stays dependency-free.
Usage
import { GlassSelect } from '@vitrumui/react/select'
const [speed, setSpeed] = useState<string | null>(null)
<GlassSelect
label="Delivery"
placeholder="Choose a speed"
value={speed}
onValueChange={setSpeed}
options={[
{ value: 'standard', label: 'Standard' },
{ value: 'express', label: 'Express' },
{ value: 'pickup', label: 'Pickup', disabled: true },
]}
/>Opening, the list swells out of the whole button, the neck between them stretches and snaps, both halves take the jolt and the options arrive one after another. Closing is the opening played backwards, frame for frame; reopen it on the way and it carries on from there. The button wears Button's glass, with its light and shadow. Once the neck lets go, the list settles into Card's frost with no light of its own: a thin line draws its edge and a soft shadow lifts it off the page. The glass is clear, so it needs something behind it to bend.
Your own popup
The stretch is not tied to a select. GlassPopup, which ships with it, puts the same motion on any control and the surface it opens (a menu, a popover):
import { GlassPopupAnchor, GlassPopupSurface, useGlassPopup } from '@vitrumui/react'
const popup = useGlassPopup()
<MenuTrigger data-vt-host className="rounded-full px-5 h-12 bg-white/60 dark:bg-white/10">
<GlassPopupAnchor popup={popup} />
Options
</MenuTrigger>
<MenuContent data-vt-popup data-vt-skip sideOffset={12} className="rounded-3xl p-1.5">
<GlassPopupSurface popup={popup} />
<div role="menu">
<MenuItem style={{ '--vt-i': 0 }}>Rename</MenuItem>
<MenuItem style={{ '--vt-i': 1 }}>Duplicate</MenuItem>
</div>
</MenuContent>GlassPopupAnchoris the first child of the control (markeddata-vt-host);GlassPopupSurfaceis the first child of the content (markeddata-vt-popup).- The content carries
data-openwhile open anddata-ending-stylewhile it closes, and stays mounted until its animations finish: UI SDK's popups do this. - Items are
role="option",role="menuitem"ordata-vt-item;--vt-iis each one's place in the queue. - The surface takes its corners from the content's own
rounded-*class; leave about 12 px between it and the control for the neck.
API reference
| Prop | Type | Default |
|---|---|---|
labelThe field's label, tied to the button. | ReactNode | — |
optionsThe choices, in order. | { value: string; label: ReactNode; disabled?: boolean }[] | — |
valueThe selected value (controlled). | string | null | — |
defaultValueThe starting value when the select keeps its own state. | string | null | — |
onValueChangeCalled with the new value. | (value: string | null) => void | — |
placeholderShown on the button while nothing is selected. | string | — |
nameSubmits the value with a form under this name. | string | — |
disabledDimmed and not interactive. | boolean | false |
classNameClasses for the field (label and button); it is 16rem wide by default. | string | — |
useGlassPopup({ matchWidth })Your own popup: keep the surface exactly as wide as its control. | boolean | false |
Accessibility
- A
comboboxbutton that opens alistbox(the WAI-ARIA select pattern), labelled bylabel. - Arrow keys, Home and End move through the options, typing a letter jumps to a match, Enter selects, Escape closes and returns focus to the button. Disabled options are skipped.
- With reduced motion the list opens and closes at once, with no stretch or jolt.
- Without WebGL2 it is a plain frosted list.