---
title: "Tabs"
description: "Switch between content panels with default, line and vertical tabs."
---

# Tabs

Switch between content panels with default, line and vertical tabs.

## Installation

Install the shared package once in your Exact app. This version is a beta.

```sh
bun add --exact @rightui/ui@0.4.0-beta.4
```

Or choose another package manager:

```sh
npm install --save-exact @rightui/ui@0.4.0-beta.4
pnpm add --save-exact @rightui/ui@0.4.0-beta.4
yarn add --exact @rightui/ui@0.4.0-beta.4
```

Exact compilation uses Bun 1.4.2. Register Geist and Newsreader, declare the font marker and add the root provider using [Installation](/docs/installation).

### Manual source setup

Install an editable copy of the complete package:

```sh
mkdir -p vendor/rightui vendor/rightui-ui
npm pack @rightui/ui@0.4.0-beta.4 --pack-destination vendor/rightui
tar -xzf ./vendor/rightui/rightui-ui-0.4.0-beta.4.tgz -C vendor/rightui-ui --strip-components=1
bun add file:./vendor/rightui-ui
```

Keep package.json, the Contract files, ui.tamber, assets and licenses together.

### Import

```contract
use Tabs, CountedTabs, TabsAdvanced from "@rightui/ui"
```

## Usage

Import Tabs, TabsAdvanced from @rightui/ui. Store its value in state and update it through the provided action callback.

## Example

```contract
use FontWeights from "@rightui/ui"
use uiFontFamily, Tabs, TabsAdvanced, CountedTabs, Button from "@rightui/ui"


component Demo
  props
    width: number
    reduced: bool
  inject
    uiWeights: FontWeights
    uiFont: string
  state current = 0
  state line = 0
  state vertical = 0
  state disabled = 0
  state rtl = 0
  state dynamic = 2
  state longFirst = false
  derive captions = longFirst ? ["Advanced settings", "Analytics", "Reports", "Home"] : ["Home", "Analytics", "Reports", "Advanced settings"]
  action selectCurrent(i: number)
    current = i
  action selectLine(i: number)
    line = i
  action selectVertical(i: number)
    vertical = i
  action selectDisabled(i: number)
    disabled = i
  action selectRTL(i: number)
    rtl = i
  action selectDynamic(i: number)
    dynamic = i
  action relabel
    longFirst = not longFirst
  action external
    dynamic = dynamic == 2 ? 3 : 2
  action clear
    dynamic = -1
  view
    column gap="ui.space-32" min-width=0
      column gap="ui.space-8" width="25rem" max-width="100%" min-width=0
        Tabs(id="tabs-demo", labels=["Overview", "Analytics", "Reports", "Settings"], selected=current, reduced=reduced, choose=selectCurrent)
        column id="tabs-demo-panel" role="tabpanel" aria-labelledby=("tabs-demo-" + current.toString()) gap="ui.space-6" padding="ui.space-16" border-width="ui.border-width" border-style="solid" border-color="ui.border" border-radius="ui.ai-radius-control"
          text (current == 0 ? "Overview" : current == 1 ? "Analytics" : current == 2 ? "Reports" : "Settings") testId="tabs-demo-title" font-size="ui.text-sm" line-height="ui.leading-control" font-weight=uiWeights.medium font-family=uiFontFamily(uiFont) data-rightui-font="body"
          text (current == 0 ? "View your key metrics and recent project activity. Track progress across all your active projects." : current == 1 ? "Explore traffic, engagement, and performance over time." : current == 2 ? "Review and download your latest reports." : "Manage your account and preferences.") font-size="ui.text-sm" line-height="ui.leading-control" color="ui.muted-foreground" font-family=uiFontFamily(uiFont) data-rightui-font="body"
          if current == 0
            text "You have 12 active projects and 3 pending tasks." font-size="ui.text-sm" line-height="ui.leading-control" color="ui.muted-foreground" margin-top="ui.space-12" font-family=uiFontFamily(uiFont) data-rightui-font="body"
      column gap="ui.space-12" min-width=0
        TabsAdvanced(id="tabs-line", label="Line", labels=["Overview", "Analytics", "Reports"], counts=[], selected=line, variant="line", vertical=false, compact=true, disabledIndices=[], direction="ltr", reduced=reduced, choose=selectLine)
        text (line == 0 ? "Overview" : line == 1 ? "Analytics" : "Reports") id="tabs-line-panel" testId="tabs-line-panel" role="tabpanel" aria-labelledby=("tabs-line-" + line.toString()) font-size="ui.text-sm" color="ui.muted-foreground" font-family=uiFontFamily(uiFont) data-rightui-font="body"
      column gap="ui.space-12" min-width=0
        row gap="ui.space-16" align-items="flex-start" min-width=0
          TabsAdvanced(id="tabs-vertical", label="Account settings", labels=["Account", "Password", "Notifications"], counts=[], selected=vertical, variant="default", vertical=true, compact=true, disabledIndices=[], direction="ltr", reduced=reduced, choose=selectVertical)
          text (vertical == 0 ? "Account" : vertical == 1 ? "Password" : "Notifications") id="tabs-vertical-panel" testId="tabs-vertical-panel" role="tabpanel" aria-labelledby=("tabs-vertical-" + vertical.toString()) padding="ui.space-8" font-size="ui.text-sm" color="ui.muted-foreground" font-family=uiFontFamily(uiFont) data-rightui-font="body"
      column gap="ui.space-12" min-width=0
        TabsAdvanced(id="tabs-disabled", label="Disabled example", labels=["Home", "Disabled", "Settings"], counts=[], selected=disabled, variant="default", vertical=false, compact=true, disabledIndices=[1], direction="ltr", reduced=reduced, choose=selectDisabled)
        text (disabled == 0 ? "Home" : "Settings") id="tabs-disabled-panel" testId="tabs-disabled-panel" role="tabpanel" aria-labelledby=("tabs-disabled-" + disabled.toString()) font-size="ui.text-sm" color="ui.muted-foreground" font-family=uiFontFamily(uiFont) data-rightui-font="body"
      column gap="ui.space-12" min-width=0
        TabsAdvanced(id="tabs-rtl", label="RTL example", labels=["Overview", "Analytics", "Reports"], counts=[], selected=rtl, variant="line", vertical=false, compact=true, disabledIndices=[], direction="rtl", reduced=reduced, choose=selectRTL)
        text (rtl == 0 ? "Overview" : rtl == 1 ? "Analytics" : "Reports") id="tabs-rtl-panel" testId="tabs-rtl-panel" role="tabpanel" aria-labelledby=("tabs-rtl-" + rtl.toString()) font-size="ui.text-sm" color="ui.muted-foreground" font-family=uiFontFamily(uiFont) data-rightui-font="body"
      column gap="ui.space-12" min-width=0
        CountedTabs(id="tabs-dynamic", labels=captions, counts=["", "3", "", ""], selected=dynamic, reduced=reduced, choose=selectDynamic)
        row flex-wrap="wrap" gap="ui.space-8"
          Button(id="tabs-relabel", label="Change labels", variant="outline", disabled=false, press=relabel)
          Button(id="tabs-external", label="Change selection", variant="outline", disabled=false, press=external)
          Button(id="tabs-clear", label="Clear selection", variant="ghost", disabled=false, press=clear)
        text (dynamic.toString()) id="tabs-dynamic-panel" testId="tabs-dynamic-panel" role="tabpanel" aria-label="Selected index" font-size="ui.text-sm" color="ui.muted-foreground" font-family=uiFontFamily(uiFont) data-rightui-font="body"

```

## API Reference

| Property | Type |
| --- | --- |
| Tabs.id | string |
| Tabs.labels | string[] |
| Tabs.selected | number |
| Tabs.reduced | bool |
| Tabs.choose | action |
| CountedTabs.id | string |
| CountedTabs.labels | string[] |
| CountedTabs.counts | string[] |
| CountedTabs.selected | number |
| CountedTabs.reduced | bool |
| CountedTabs.choose | action |
| TabsAdvanced.id | string |
| TabsAdvanced.label | string |
| TabsAdvanced.labels | string[] |
| TabsAdvanced.counts | string[] |
| TabsAdvanced.selected | number |
| TabsAdvanced.variant | string |
| TabsAdvanced.vertical | bool |
| TabsAdvanced.compact | bool |
| TabsAdvanced.disabledIndices | number[] |
| TabsAdvanced.direction | string |
| TabsAdvanced.reduced | bool |
| TabsAdvanced.choose | action |

## Source

File: packages/ui/tabs.contract

```contract
use FontWeights from "./typography-context.contract"
use uiFontFamily from "./typography-context.contract"
component Tabs
  props
    id: string
    labels: string[]
    selected: number
    reduced: bool
    choose: action
  view
    TabStrip(id=id, labels=labels, counts=[], selected=selected, reduced=reduced, choose=choose, variant="default", vertical=false, compact=true, disabledIndices=[], direction="ltr", label="Sections")

component CountedTabs
  props
    id: string
    labels: string[]
    counts: string[]
    selected: number
    reduced: bool
    choose: action
  view
    TabStrip(id=id, labels=labels, counts=counts, selected=selected, reduced=reduced, choose=choose, variant="default", vertical=false, compact=false, disabledIndices=[], direction="ltr", label="Sections")

component TabsAdvanced
  props
    id: string
    label: string
    labels: string[]
    counts: string[]
    selected: number
    variant: string
    vertical: bool
    compact: bool
    disabledIndices: number[]
    direction: string
    reduced: bool
    choose: action
  view
    TabStrip(id=id, labels=labels, counts=counts, selected=selected, reduced=reduced, choose=choose, variant=variant, vertical=vertical, compact=compact, disabledIndices=disabledIndices, direction=direction, label=label)

component TabStrip
  props
    id: string
    label: string
    labels: string[]
    counts: string[]
    selected: number
    reduced: bool
    choose: action
    variant: string
    vertical: bool
    compact: bool
    disabledIndices: number[]
    direction: string
  inject
    uiWeights: FontWeights
    uiFont: string
  state markerX = 0
  state markerY = 0
  state markerWidth = 0
  state markerHeight = 0
  state ready = false
  state hairline = 1
  state lineThickness = 2
  action measureStroke(w: number, h: number)
    hairline = w
    lineThickness = h
  derive valid = selected >= 0 and selected < labels.length
  derive enabled = range(labels.length).filter(i => not disabledIndices.includes(i))
  derive measurementKey = selected.toString() + "|" + labels.map(v => v.length.toString() + ":" + v).join("") + "|" + counts.map(v => v.length.toString() + ":" + v).join("") + "|" + variant + "|" + vertical.toString() + "|" + compact.toString() + "|" + direction
  action measure(w: number, h: number)
    if valid
      let container = frame(id)
      let target = frame(id + "-" + selected.toString())
      if container.width > 0 and target.width > 0 and target.height > 0
        markerX = target.x - container.x
        markerY = target.y - container.y
        markerWidth = target.width
        markerHeight = target.height
        ready = true
      else
        ready = false
    else
      ready = false
  action pick(i: number)
    if not disabledIndices.includes(i)
      choose(i)
  action keys(k: string)
    let forward = vertical ? k == "ArrowDown" : direction == "rtl" ? k == "ArrowLeft" : k == "ArrowRight"
    let backward = vertical ? k == "ArrowUp" : direction == "rtl" ? k == "ArrowRight" : k == "ArrowLeft"
    if enabled.length > 0 and (forward or backward or k == "Home" or k == "End")
      preventDefault()
      let current = enabled.indexOf(selected)
      let position = k == "Home" ? 0 : k == "End" ? enabled.length - 1 : forward ? (current + 1) % enabled.length : (max(0, current) + enabled.length - 1) % enabled.length
      match enabled.at(position)
        case some(next)
          choose(next)
          focus(id + "-" + next.toString())
        case none
          ready = false
  view
    scroll id=(id + "-viewport") testId=(id + "-viewport") max-width="calc(100% + ui.space-8)" min-width="0px" align-self="flex-start" overflow-x="auto" overflow-y="hidden" padding="ui.space-4" margin="ui.space-negative-4" box-sizing="border-box" -webkit-font-smoothing="antialiased"
      view id=id testId=id resize=measure position="relative" display="flex" flex-direction=(vertical ? "column" : "row") flex-wrap="nowrap" role="tablist" aria-label=label aria-orientation=(vertical ? "vertical" : "horizontal") direction=direction appearance="none" padding="ui.space-3" gap=(variant == "line" ? "ui.space-4" : "0px")
        background-color=(variant == "line" ? "transparent" : "ui.muted") border="0" border-radius=(variant == "line" ? "0px" : "ui.radius-control") width="auto" min-width="0px" align-items=(vertical ? "stretch" : "center") height=(vertical ? "auto" : compact ? "ui.space-32" : "ui.space-36") box-sizing="border-box"
        view position="absolute" width="ui.border-width" height="ui.border-strong-width" opacity=0 aria-hidden=true pointer-events="none" resize=measureStroke
        if ready and valid
          view id=(id + "-indicator") testId=(id + "-indicator") aria-hidden=true pointer-events="none"
            position="absolute" left=(variant == "line" ? vertical ? markerX + markerWidth + hairline : markerX + hairline : markerX) top=(variant == "line" ? vertical ? markerY + hairline : markerY + markerHeight + lineThickness : markerY)
            width=(variant == "line" ? vertical ? "ui.border-strong-width" : max(0, markerWidth - 2 * hairline) : markerWidth) height=(variant == "line" ? vertical ? max(0, markerHeight - 2 * hairline) : "ui.border-strong-width" : markerHeight)
            border-radius=(variant == "line" ? "0px" : "ui.radius-item") background-color=(variant == "line" ? "ui.foreground" : "ui.tab-active") border-width=(variant == "line" ? "0px" : "ui.border-width") border-style="solid" border-color="ui.tab-active-border" box-sizing="border-box"
            box-shadow=(variant == "line" ? "none" : "ui.shadow-control")
            -exact-layout-transition=(reduced ? "none" : "ui.duration-normal ui.easing")
        for caption, i in labels key=caption
          button id=(id + "-" + i.toString()) testId=(id + "-" + i.toString()) appearance="none" disabled=disabledIndices.includes(i)
            role="tab" aria-selected=(selected == i) aria-controls=(id + "-panel")
            tabindex=(not disabledIndices.includes(i) and (selected == i or not valid and enabled.indexOf(i) == 0) ? 0 : -1) key=keys press=pick(i)
            position="relative" flex="0 0 auto" box-sizing="border-box" display="flex" align-items="center" justify-content=(vertical ? "flex-start" : "center") gap="ui.space-6"
            min-width="auto" width="auto" height=(vertical ? compact ? "ui.tabs-height-vertical-compact" : "ui.tabs-height-vertical-default" : compact ? "ui.tabs-height-horizontal-compact" : "ui.tabs-height-horizontal-default") min-height="0px"
            border-width="ui.border-width" border-style="solid" border-color="transparent" border-radius="ui.radius-item" padding=(compact ? "ui.space-2 ui.space-6" : "ui.space-4 ui.space-8") white-space="nowrap"
            background-color=(not ready and selected == i and variant != "line" ? "ui.tab-active" : "transparent") cursor="pointer" pointer-events=(disabledIndices.includes(i) ? "none" : "auto")
            color=(selected == i ? "ui.foreground" : "ui.tab-inactive") font-size="ui.text-sm" line-height="ui.leading-control" font-weight=uiWeights.medium
            transition=(reduced ? "none" : "color ui.duration-fast ui.easing, border-color ui.duration-fast ui.easing, box-shadow ui.duration-fast ui.easing")
            :focus-visible
              border-color="ui.focus"
              box-shadow="ui.shadow-focus"
            :hover
              color="ui.foreground"
            :disabled
              opacity="ui.opacity-disabled"
            text caption white-space="nowrap" font-family=uiFontFamily(uiFont) data-rightui-font="body"
            match counts.at(i)
              case some(count)
                if count != ""
                  text count display="flex" align-items="center" justify-content="center" width="ui.space-20" min-width="ui.space-20" height="ui.space-20" box-sizing="border-box" padding="0px ui.space-4" border-width="ui.border-width" border-style="solid" border-color="transparent" border-radius="ui.radius-full" background-color="ui.tab-count" color="ui.foreground" font-size="ui.text-xs" line-height="ui.leading-heading" font-weight=uiWeights.medium font-family=uiFontFamily(uiFont) data-rightui-font="body"
              case none
                view display="none"
        for revision in [measurementKey] key=revision
          view resize=measure position="absolute" inset=0 pointer-events="none" aria-hidden=true

```
