Tabs Updated
A segmented control whose selection travels as a glass lens.
Latest change Improved v3.1.2 The light a Tabs lens takes as it lands, and the one a Slide to Confirm thumb takes when the slide ends in success, now peak in about 75 ms and are gone in about 0.7 s, where they took some 200 ms to peak and 1.4 s to fade. They have a timing of their own (GLOW_BRIEF in engine.ts, asked for with light(view, { brief: true })); the light of a press on a button is as it was.
- v3.1.2 Improved The light a Tabs lens takes as it lands, and the one a Slide to Confirm thumb takes when the slide ends in success, now peak in about 75 ms and are gone in about 0.7 s, where they took some 200 ms to peak and 1.4 s to fade. They have a timing of their own (
GLOW_BRIEFinengine.ts, asked for withlight(view, { brief: true })); the light of a press on a button is as it was. - v3.0.20 Fixed The soft light a lens takes as it lands no longer goes out in one step near its end. The lens was handed back to the flat highlight as soon as it had stopped moving, with some of the light still on it; it now stays until the light has faded.
- v3.0.16 Fixed On a phone under 360px the first example takes the small size: its four large segments were cut off at both sides.
- v3.0.9 Improved Chosen with an arrow key, the lens is on the new option at once instead of travelling to it. A press or a drag keeps the travel. A second finger on the options no longer moves the lens or chooses for the first.
- v2.3.6 Improved A label now changes colour at the edge of the lens, not over time. Wherever the lens covers a label it reads in the selected colour, while the glass is clear too, and everywhere else in its own: a label the lens is half over is two colours, split along the glass. Before, the label the lens left faded over 0.2 s and labels under the clear lens stayed in their unselected colour. With GlassLens on your own markup the same holds wherever the selected colour reads on the track at least as well as the label's own; a dark label on a white pill over a dark track keeps its own colour under clear glass, as before.
- v2.3.2 Improved Press and hold another option and glass appears there, under the pointer: it grows out of the press, already clear, while the selected highlight fades. Let go and it settles as the new selection; drag it first and it follows the pointer. A press that is cancelled lets the glass go back into the point it grew from, and the highlight returns. Before, the glass opened over the selected option, away from the press. A quick click still sends the lens travelling, and GlassLens does the same for your own options, in a column too.
- All changes→
Distance this week
Use it for
- Switching a view or a range in place: Day / Week / Month, List / Grid.
- Two to five short options.
Not for
- Navigating between pages: use links.
- Long lists of options: use a select.
Installation
npx shadcn-svelte@latest add https://liquidglass.pulse.city/r/tabs.jsonThe behaviour (one tab stop, arrow keys, a hidden radio per option for forms) comes from UI SDK's segmented control, so Tabs 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 { GlassTabs } from '@/components/liquid-glass'
const [view, setView] = useState('week')
<GlassTabs
aria-label="Range"
value={view}
onValueChange={setView}
options={[
{ value: 'day', label: 'Day' },
{ value: 'week', label: 'Week' },
]}
/>Your own markup
Already have tabs (Radix Tabs, your own radio group)? Put the lens on them with GlassLens, which ships with GlassTabs:
- The container is
relative isolateand<GlassLens value={value} />is its first child. - Options carry
role="radio"orrole="tab"(Radix Tabs works as is) - The selected option contains the resting highlight, marked
data-glass-highlight. Its background colour is the lens colour and its corners are the lens corners:rounded-fulltravels as a pill,rounded-lgas a rounded rectangle. - Hide the highlight while the lens moves:
[[data-glass-moving]_&]:opacity-0. - Under the lens a label reads in the selected colour, cut to the shape of the glass; give the selected label its unselected colour while the lens is away from it with
[[data-glass-traveling]_&]:…, and leave colour transitions off the labels.
per year, four months free
API reference
| Prop | Type | Default |
|---|---|---|
options The segments. | { value, label, icon?, aria-label? }[] | — |
value Selected value (controlled). | string | null | — |
onValueChange Called with the new value. | (value) => void | — |
aria-label Required: names the group for screen readers. | string | — |
name Submits the selected value under this name with the form around it. | string | — |
size Segment height 28, 32 or 40 px. | 'sm' | 'md' | 'lg' | 'md' |
highlightClassName Classes of the resting pill; its background is the lens colour. | string | 'bg-white dark:bg-neutral-700' |
GlassLens value Your own markup: the selected value; any change moves the lens. | string | number | null | — |
GlassLens disabled No lens; the highlight simply jumps. | boolean | false |
Accessibility
- Radiogroup pattern: one tab stop, arrow keys move the selection.
- Icon-only options take an
aria-labeleach. - With reduced motion the pill simply jumps.
Liquid Glass Svelte is open source and MIT licensed. If it saves you time, you can support the project.