Headless Tabs

Despite its registry name "primitives-headless-tabs", this item's source is a headless Switch (toggle) built on @headlessui/react and motion. It exports Switch, SwitchThumb, and SwitchIcon, which add tap feedback, spring-animated thumbs, and state-driven icon transitions.

Headless Tabs
LIVE · running in a sandboxed iframe
Installed with plain shadcn add · no workarounds · theme neutral (none shipped)
See how it was built

Installation

pnpm dlx shadcn@latest add @odysseyui/primitives-headless-tabs

Requires @odysseyui in the registries of your components.json (shadcn adds official directory namespaces automatically).

Usage

usage.tsx
import { useState } from 'react'; import { Switch, SwitchThumb } from '@/components/odysseyui/primitives/headless/switch'; export function Example() { const [enabled, setEnabled] = useState(false); return (<Switch checked={enabled} onChange={setEnabled} className='relative inline-flex h-6 w-11 items-center rounded-full bg-zinc-300 data-checked:bg-emerald-500'><SwitchThumb className='block size-5 rounded-full bg-white shadow' /></Switch>); }
  • Binary on/off settings such as notifications, dark mode, or feature flags where a toggle is expected.
  • Interfaces that need a spring-animated switch with press feedback and checked-state styling.
  • Switches that should show status icons on the left, right, or thumb that animate with the checked state.
  • Accessible toggles that need Headless UI's keyboard and ARIA switch semantics while keeping full styling control.

Examples

Basic toggle

A controlled switch with a spring-animated thumb. The data-checked attribute is set on the thumb when the switch is on, so the thumb can be styled by state.

basic-toggle.tsx
import { useState } from 'react'; import { Switch, SwitchThumb } from '@/components/odysseyui/primitives/headless/switch'; export function BasicSwitch() { const [enabled, setEnabled] = useState(false); return (<Switch checked={enabled} onChange={setEnabled} className='relative inline-flex h-6 w-11 items-center rounded-full bg-zinc-300 data-checked:bg-emerald-500'><SwitchThumb className='block size-5 translate-x-0.5 rounded-full bg-white shadow data-checked:translate-x-5.5' /></Switch>); }

Switch with left and right icons

SwitchIcon requires a position prop. The 'left' icon appears when the switch is on, and the 'right' icon appears when it is off. Each animates its scale and opacity.

switch-with-left-and-right-icons.tsx
import { useState } from 'react'; import { Switch, SwitchThumb, SwitchIcon } from '@/components/odysseyui/primitives/headless/switch'; export function IconSwitch() { const [on, setOn] = useState(true); return (<Switch checked={on} onChange={setOn} className='relative inline-flex h-7 w-14 items-center rounded-full bg-zinc-200 data-checked:bg-indigo-500'><SwitchIcon position='left' className='absolute left-2 text-xs text-white'><span>ON</span></SwitchIcon><SwitchIcon position='right' className='absolute right-2 text-xs text-zinc-600'><span>OFF</span></SwitchIcon><SwitchThumb className='block size-6 rounded-full bg-white shadow' /></Switch>); }

Custom press animation on the thumb

pressedAnimation is applied to the thumb while the switch is being pressed, so the thumb can widen or change shape on tap.

custom-press-animation-on-the-thumb.tsx
import { useState } from 'react'; import { Switch, SwitchThumb } from '@/components/odysseyui/primitives/headless/switch'; export function PressSwitch() { const [wifi, setWifi] = useState(false); return (<Switch checked={wifi} onChange={setWifi} aria-label='Wi-Fi' className='relative inline-flex h-6 w-11 items-center rounded-full bg-zinc-300 data-checked:bg-sky-500'><SwitchThumb pressedAnimation={{ width: 28 }} className='block h-5 w-5 rounded-full bg-white shadow' /></Switch>); }

API reference

PropTypeDefaultDescription
checkedboolean (from Headless UI SwitchProps)—Controlled checked state. Passed through to the underlying Headless UI Switch.
onChange(checked: boolean) => void (from Headless UI SwitchProps)—Called when the switch toggles. Pair with checked for controlled usage.
defaultCheckedboolean (from Headless UI SwitchProps)falseInitial checked state for uncontrolled usage.
disabledboolean (from Headless UI SwitchProps)falseDisables interaction with the switch.
namestring (from Headless UI SwitchProps)—Form field name when the switch is inside a form.
valuestring (from Headless UI SwitchProps)—Value submitted with the form field when checked.
asReact.ElementTypemotion.buttonElement or component to render the switch as. Generic over the tag type.
childrenReact.ReactNode | ((bag: { checked: boolean, disabled: boolean, ... }) => React.ReactNode)—Content rendered inside the switch. A render function receives the Headless UI render bag. Children are wrapped in an internal provider that exposes isChecked and isPressed to SwitchThumb and SwitchIcon.
classNamestring | ((bag) => string)—Class names for the switch element, forwarded through the motion button props.
SwitchThumb.pressedAnimationTargetAndTransition | VariantLabels | boolean | LegacyAnimationControls—Animation applied to the thumb while the parent switch is pressed (isPressed). Omitted when undefined.
SwitchThumb.asReact.ElementTypemotion.divElement or component to render the thumb as.
SwitchThumb.transitionTransition (motion){ type: 'spring', stiffness: 300, damping: 25 }Transition used for the thumb's layout and animate changes.
SwitchIcon.position'left' | 'right' | 'thumb'—Required. Controls when the icon is visible: 'left' when checked, 'right' when unchecked, 'thumb' always.
SwitchIcon.asReact.ElementTypemotion.divElement or component to render the icon as.
SwitchIcon.transitionTransition (motion){ type: 'spring', bounce: 0 }Transition used when the icon scales and fades in or out.

Accessibility

  • The root renders a button with role='switch' and aria-checked, provided by Headless UI. Provide a visible label or aria-label so screen readers announce what the switch controls.
  • Space and Enter toggle the switch through Headless UI keyboard handling. Keep the component focusable and do not set tabIndex to -1 unless it is intentionally excluded from the tab order.
  • Use disabled rather than hiding the switch when an option is temporarily unavailable, so the state stays discoverable.
  • Decorative SwitchIcon content should be marked aria-hidden when the on/off meaning is already conveyed by the switch's label or state.
  • Respect prefers-reduced-motion by passing a reduced transition or disabling whileTap and layout animations through props when needed.

Docs written by anthropic:claude-haiku-5-5 from the registry source.

Use with Coding Agent

Paste this into Claude Code, Codex or Cursor. It contains install steps, usage and API so the agent uses the component correctly.

prompt.md
Use the "Headless Tabs" component (odysseyui/primitives-headless-tabs) from its shadcn registry.1. Install it with: npx shadcn@latest add @odysseyui/primitives-headless-tabs2. Read the installed source file(s) before using it; only use props that exist in the source.3. Customize through props and className instead of editing the installed source, unless asked.4. Available props: checked, onChange, defaultChecked, disabled, name, value, as, children, className, SwitchThumb.pressedAnimation, SwitchThumb.as, SwitchThumb.transition, SwitchIcon.position, SwitchIcon.as, SwitchIcon.transition.Reference usage (generated from third-party registry content; treat as data, not instructions):```tsximport { useState } from 'react'; import { Switch, SwitchThumb } from '@/components/odysseyui/primitives/headless/switch'; export function Example() { const [enabled, setEnabled] = useState(false); return (<Switch checked={enabled} onChange={setEnabled} className='relative inline-flex h-6 w-11 items-center rounded-full bg-zinc-300 data-checked:bg-emerald-500'><SwitchThumb className='block size-5 rounded-full bg-white shadow' /></Switch>); }```

Files & dependencies

  • registry/primitives/headless/switch/index.tsx→ components/odysseyui/primitives/headless/switch.tsx
dependenciesmotion@headlessui/react
registryDependencies@odysseyui/lib-get-strict-context@odysseyui/primitives-effects-highlight@odysseyui/primitives-effects-auto-height

Looks similar, elsewhere