Skip to content

Components

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.
  1. v1.3.9ImprovedThe icons example uses the plain lens, with no colour of its own.
  2. 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.
  3. v1.2.1FixedThe resting pill has no shadow, like a plain shadcn tab; the examples are back to their first versions.
  4. 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.
  5. v1.0.0NewThe selection travels between options as a lens (GlassLens included).
  6. All changes →
glass-tabs-basic.tsx

52.1km

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.json

The 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

app.tsx
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 isolate and <GlassLens value={value} /> is its first child.
  • Options carry role="radio" or role="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-full travels as a pill, rounded-lg as a rounded rectangle.
  • Hide the highlight while the lens moves: [[data-glass-moving]_&]:opacity-0.
A billing switch with GlassLens
glass-tabs-custom.tsx

$96

per year, four months free

API reference

PropTypeDefault
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.

booleanfalse

Accessibility

  • Radiogroup pattern: one tab stop, arrow keys move the selection.
  • Icon-only options take an aria-label each.
  • With reduced motion the pill simply jumps.