Tabs

updated

Panels switched by a row or column of tabs, with an indicator that slides to the active one.

Demo

Open Props in the corner of the example to switch the list's variant and size.

color on TabsList paints the line under the active tab, in Button's colours or your own. The line takes the colour's text shade, so a thin warning line still shows on the page. primary is the default; neutral gives the black underline of shadcn's tabs. The tab labels stay in the text colours, so a bar of coloured labels doesn't compete with the content. The pill indicator is a raised surface rather than a colour, so it ignores color; its fill is --tabs-pill, the page background in the light theme and a lighter wash under .dark.

size goes from xs (28px) to xl (48px) and scales padding, text and icons with it.

Installation

Usage

<script setup lang="ts">
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'
</script>

<template>
  <Tabs default-value="account">
    <TabsList>
      <TabsTrigger value="account">Account</TabsTrigger>
      <TabsTrigger value="password">Password</TabsTrigger>
    </TabsList>
    <TabsContent value="account">Account settings.</TabsContent>
    <TabsContent value="password">Password settings.</TabsContent>
  </Tabs>
</template>

Tabs is Reka UI's tabs with kappa-ui's styles. TabsList sets the look — variant, color and size — and draws the indicator, which slides to the active tab. The indicator is measured after the page loads, so in server-rendered HTML the active tab is marked by its text colour until then.

Examples

Line

variant="line" drops the track and underlines the active tab.

The list is only as wide as its tabs; give it w-full to run the divider under the full width.

Line
Your projects at a glance.

Vertical

With orientation="vertical" on Tabs, the list becomes a column beside the panels, and the up and down arrow keys move between tabs.

Vertical
Name, language and time zone.
Name, language and time zone.

With icons

An icon before the label takes the size's icon size.

With icons

Keep inactive panels mounted

By default a hidden panel's content is removed from the page. With :unmount-on-hide="false" it stays mounted and hidden, so a form keeps what was typed into it.

Keeping panels mounted

API Reference

Every part accepts class, merged over its base classes.

Data attributes

data-slotAttributesDescription
tabsdata-orientationThe root.
tabs-listdata-variant, data-color, data-size, data-orientation, aria-orientationThe row or column of tabs.
tabs-indicator—The pill or line under the active tab.
tabs-triggerdata-state, data-disabled, data-orientationA tab.
tabs-contentdata-state, data-orientationA panel.

Accessibility

The list is a tablist, each trigger a tab, each panel a tabpanel labelled by its tab.

KeyAction
TabMoves focus to the active tab, then into its panel.
→ ←In a horizontal list, moves to the next or previous tab, skipping disabled ones and wrapping around. In right-to-left they swap.
↓ ↑The same in a vertical list.
Home / EndMoves to the first or last tab.
Enter / SpaceSelects the focused tab when activation-mode is manual.

Changelog

  1. registry 0.22.0

    b3cd937 — Components follow .dark through tokens only. The Tabs pill fills with the new --tabs-pill token (the page background, and --input at 30% under .dark) instead of dark:bg-input/30, and shimmer takes its brighter dark highlight from a .dark value of --shimmer-color instead of @variant dark. Both now switch with the .dark class even in a project whose own dark variant is something else.

    85b907b — A SwipeView page that receives focus (when the page holding it leaves the frame, or a Tabs panel reached with Tab) drops the browser's default outline: it shows the kit's inset focus ring after a keyboard action and nothing after a swipe, a tap or a click.

    b81d4d6 — The TabsList indicator follows the active trigger when a tab is inserted before it or removed: the list watches its children and asks Reka's indicator to measure again, which a fixed-width list never prompted.

    81c6407 — The pill TabsList's thumb stays on the triggers when a class such as p-2 changes the list's padding: it is centred on the list's cross axis instead of sitting 4px in.

    88f0beb — flex-none (or any flex-* class) on a horizontal pill TabsTrigger now wins over the stretch the list gives its triggers; the list passes the stretch down through --tabs-trigger-flex.

  2. core 0.16.0

    b3cd937 — Components follow .dark through tokens only. The Tabs pill fills with the new --tabs-pill token (the page background, and --input at 30% under .dark) instead of dark:bg-input/30, and shimmer takes its brighter dark highlight from a .dark value of --shimmer-color instead of @variant dark. Both now switch with the .dark class even in a project whose own dark variant is something else.

  3. registry 0.21.0

    e5495ef — size works the same way everywhere. Every component exports its size type (AlertSize, BadgeSize, CardSize, CheckboxSize, RadioSize, SwitchSize, EmptySize, InputFloatingSize, ItemSize, ListboxSize, SeparatorSize, SliderSize, StepperSize, TabsSize, TextareaSize, TimelineSize) and the props take it without null; Button-based parts take ButtonSize, Input TextControlSize, SelectTrigger SelectSize and Tree TreeSize. ToggleGroup and ToolbarToggleGroup carry data-size on the group as well. Table's row heights moved into tableSize, so a class on DataTable's ui.table overrides --table-row-h at every size, not only at md.

  4. registry 0.17.0

    6c50288 — New SwipeViews: pages that follow the finger, the way native apps page between tabs. It holds the page in the frame in v-model, pairs with Tabs on the same model, and lays its SwipeViews out in a row that a swipe or a flick moves along. layout="stack" lays the pages on top of each other, each sliding in over the one before it, as in a navigation stack. The frame and every page carry CSS variables for layouts and effects of your own. SwipeViewsSwipeArea adds a strip at an edge, and swipe-area-only makes it the only way to swipe. The mechanism underneath comes as its own item, swipe-snap, with useSwipeSnap for sheets, galleries and pagers of your own.

  5. registry 0.13.0

    5a478d3 — Checkbox, Radio, Switch, Slider, Progress, Stepper and TabsList take color: primary (the default), neutral, destructive, success, warning, info, or any name you declare on [data-slot][data-color="<name>"], as on Button. The root carries data-color. Whatever they draw straight on the page takes the colour's --tone-text: a checked edge, the radio's dot, the default slider's range and thumb, the progress bar and the tab line. That keeps a bright success, warning or info at 3:1 against the page. Fills with something on them, like the checked box, the switch track and the active step, keep --tone. On the choice controls the unchecked edge stays --input and an invalid control still turns destructive. Keyboard focus rings a control in a colour other than primary in its --tone-text, red once it's invalid. CheckboxGroup and RadioGroup pass their color to every control in them without one, and ChoiceGroup takes color for the selected card's edge, the focused card's ring and the selected row's tint. Switch, Checkbox, Radio and Slider now set data-size, md by default. They need the @kappa-ui/core release that lets tone-control follow data-color.

    Recoloured Switch, Checkbox, Radio or Slider with class="[--tone:…] [--tone-foreground:…]", as the theming page used to suggest? Their edges and marks now read --tone-text, so add [--tone-text:…] to the class, or use color.

  6. registry 0.12.0

    c79028b — The control scale is now a set of tokens: --control-height-*, --control-padding-*, --control-icon-* and --control-gap-* for xs to xl, added to :root by the tokens item. Button, Input, InputFloating, Select, Combobox, InputNumber, TagsInput, PinInput, InputTime, InputGroup, Menu, Tabs, ColorPicker and Pagination read them, so overriding one on :root resizes every control of that size.

    Some sizes that strayed from the scale now follow it. Button icons are 20px at lg and xl instead of 16px, and so are the icons of Toggle, ToggleGroup, Toolbar and Pagination at those sizes. The gap between an icon and its label is 6, 8, 8, 10 and 12px from xs to xl, about half the icon, everywhere that has one: Button and the components built on it (where it was 4, 6, 8, 8 and 8px), Menu items and the Select, Combobox and Command lists (8, 10, 12, 12 and 12px), and Tabs triggers (6, 8, 8, 8 and 10px). Inset and checkbox or radio items move their labels with it, so they stay in line with items that have an icon. Everything else keeps its size.