Tabs

Free

A card's panels switched by the locked segmented control: the picked pill slides to the next tab with its words changing color as it passes, and counts sit after the words.

npx shadcn@latest add https://pixilui.com/r/tabs.json

Preview

The pill slides to the next tab, its words changing color exactly as it passes.
Size

When to use

Use it when

  • Switching the panels of one card: a run's Overview, Trace, Logs and Cost; an agent's General, Tools, Permissions and Memory.
  • Two to five short tab names, with a count where it helps (Trace 7).

Use something else when

  • Picking a value that changes the same view: use the segmented control.
  • Moving between pages: use links in the navigation.
  • More than five panels: use a list that opens each one.

Installation

Terminal
npx shadcn@latest add https://pixilui.com/r/tabs.json

Adds tabs.tsx with kbd.tsx, tooltip.tsx and segmented-control.tsx, and installs clsx and tailwind-merge. The URL works in any app with a components.json, with no registry to add first.

Usage

example.tsx
import { Tabs } from "@/components/pixilui/tabs";

<Tabs onValueChange={onValueChange}>Save changes</Tabs>

The list is as wide as its tabs. Keep tab names short so it fits at 375 wide; panels fill their container.

API reference

PropTypeDefault
valuestring–The open tab, controlled. Pair with onValueChange.
defaultValuestring–The tab open at first when uncontrolled. Defaults to the first option of the list.
onValueChange(value: string, details: { by: SegmentedPickBy }) => void | Promise<void>–Runs when a tab is picked, with how: pointer or key.
childrenReactNode–The list and its panels.

Also takes every native <div> attribute except defaultValue, onChange, and a ref.

Keyboard

TabMoves focus to the open tab, then into its panel.
← →Opens the previous or next tab at once, wrapping.
Home EndOpens the first or last tab.

Accessibility

  • A tablist of tabs with aria-selected and aria-controls; each panel is role tabpanel, named by its tab, focusable so long content can be scrolled by keyboard.
  • One tab stop in the list: the open tab. Hidden panels are hidden.
  • The pill and the clipped copy of the words are aria-hidden.

Motion

  • A click slides the pill to the new tab and resizes it, 240ms on ease-in-out, interruptibly; the words in the picked color move with it.
  • Keyboard picks jump. A list inside a panel that was hidden places itself at once when it shows.
  • Reduced motion: everything at once.
Segmented controlThe pill slides to your pick; a time-boxed choice says when it ends and switches back.
Dropdown menuA highlight glides between rows, and each row's icon plays as it lands.

PixilUI Pro opens soon. The first 20 licenses are $99.