Tabs
A segmented control whose selection travels as a glass lens.
glass-tabs-basic.tsx
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
Coming soon
npm install @vitrumui/reactNo dependencies
Usage
app.tsx
import { GlassTabs } from '@vitrumui/react/tabs'
const [view, setView] = useState('week')
<GlassTabs
aria-label="Range"
value={view}
onValueChange={setView}
options={[
{ value: 'day', label: 'Day' },
{ value: 'week', label: 'Week' },
]}
/>Examples
Coming soon
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-vt-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-vt-moving]_&]:opacity-0.
glass-tabs-custom.tsx
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 | — |
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.