Tabs
A segmented control whose selection travels as a glass lens.
Latest changeImprovedv1.3.9The icons example uses the plain lens, with no colour of its own.
- v1.3.9ImprovedThe icons example uses the plain lens, with no colour of its own.
- v1.3.2ImprovedIn the Tabs examples the figure above the control rolls to its new value with NumberFlow instead of swapping. The examples now import
@number-flow/react; the component itself still needs no package. - v1.2.1FixedThe resting pill has no shadow, like a plain shadcn tab; the examples are back to their first versions.
- v1.1.1FixedGlassLens takes its corners from the highlight: rectangular options (
rounded-lg) get a rounded-rectangle lens instead of a pill, its corners grow as it swells, and between options of different sizes they travel with the size. GlassTabs keeps its pill. - v1.0.0NewThe selection travels between options as a lens (GlassLens included).
- 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@latest add https://onemorethink.dev/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.
per year, four months free
API reference
| Prop | Type | Default |
|---|---|---|
optionsThe segments. | { value, label, icon?, aria-label? }[] | — |
valueSelected value (controlled). | string | null | — |
onValueChangeCalled with the new value. | (value) => void | — |
aria-labelRequired: names the group for screen readers. | string | — |
nameSubmits the selected value under this name with the form around it. | string | — |
sizeSegment height 28, 32 or 40 px. | 'sm' | 'md' | 'lg' | 'md' |
highlightClassNameClasses of the resting pill; its background is the lens colour. | string | 'bg-white dark:bg-neutral-700' |
GlassLens valueYour own markup: the selected value; any change moves the lens. | string | number | null | — |
GlassLens disabledNo 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.