# Tabs

> Switches between views of the same content.

Tabs switch between views of the same content, such as the summary, releases and royalties of one artist.

## When to use

- Use tabs for 2 to 6 views that sit at the same level.
- Keep the content of every tab related; use separate pages for unrelated content.
- Don't use tabs as steps of a process; use a stepper.

_Live preview of the React and Vue versions: https://design.sosialoka.tech/components/tabs/_

## Anatomy

1. Active tab
2. Indicator on primary
3. Tab
4. Panel

A row of labels over a `border` line, and the content of the active tab below it. The active tab has `foreground` text and a 2px `primary` line under it; the others use `muted-foreground`. Tabs are 36px tall and never sit on a pill.

## Variants

There is one style, horizontal or vertical (`orientation="vertical"`). In vertical tabs the line moves to the right edge.

## Props

| React | Vue | Flutter | Type | Default | Use |
| --- | --- | --- | --- | --- | --- |
| `defaultValue` / `value` | `default-value` / `v-model` | `value` | string | none | The active tab. |
| `onValueChange` | `@update:model-value` | `onChanged` | function | none | Runs when the tab changes. |
| `orientation` | `orientation` | none | `horizontal` \| `vertical` | `horizontal` | Direction of the tab list. |

## Code

**React**
```tsx
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"

export default function TabsDemo() {
  return (
    <Tabs defaultValue="ringkasan" className="w-full max-w-md">
      <TabsList>
        <TabsTrigger value="ringkasan">Ringkasan</TabsTrigger>
        <TabsTrigger value="rilis">Rilis</TabsTrigger>
        <TabsTrigger value="royalti">Royalti</TabsTrigger>
      </TabsList>
      <TabsContent value="ringkasan" className="pt-3 text-muted-foreground">12 rilis aktif bulan ini.</TabsContent>
      <TabsContent value="rilis" className="pt-3 text-muted-foreground">3 rilis menunggu dikirim.</TabsContent>
      <TabsContent value="royalti" className="pt-3 text-muted-foreground">Laporan Oktober sudah masuk.</TabsContent>
    </Tabs>
  )
}
```

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

<template>
  <Tabs default-value="ringkasan" class="w-full max-w-md">
    <TabsList>
      <TabsTrigger value="ringkasan">Ringkasan</TabsTrigger>
      <TabsTrigger value="rilis">Rilis</TabsTrigger>
      <TabsTrigger value="royalti">Royalti</TabsTrigger>
    </TabsList>
    <TabsContent value="ringkasan" class="pt-3 text-muted-foreground">12 rilis aktif bulan ini.</TabsContent>
    <TabsContent value="rilis" class="pt-3 text-muted-foreground">3 rilis menunggu dikirim.</TabsContent>
    <TabsContent value="royalti" class="pt-3 text-muted-foreground">Laporan Oktober sudah masuk.</TabsContent>
  </Tabs>
</template>
```

**Flutter**
```dart
import 'package:flutter/widgets.dart';
import 'package:shadcn_ui/shadcn_ui.dart';

class TabsDemo extends StatelessWidget {
  const TabsDemo({super.key});

  @override
  Widget build(BuildContext context) {
    return ShadTabs<String>(
      value: 'ringkasan',
      // Tabs share the bar width equally; leave room for the longest label.
      tabBarConstraints: const BoxConstraints(maxWidth: 520),
      tabs: const [
        ShadTab(value: 'ringkasan', content: Text('12 rilis aktif bulan ini.'), child: Text('Ringkasan')),
        ShadTab(value: 'rilis', content: Text('3 rilis menunggu dikirim.'), child: Text('Rilis')),
        ShadTab(value: 'royalti', content: Text('Laporan Oktober sudah masuk.'), child: Text('Royalti')),
      ],
    );
  }
}
```

## Install

**React**
```bash
npx shadcn@latest add https://design.sosialoka.tech/r/react/tabs.json
```

**Vue**
```bash
npx shadcn-vue@latest add https://design.sosialoka.tech/r/vue/tabs.json
```

## Accessibility

- Renders `role="tablist"`, `tab` and `tabpanel`, with `aria-selected` on the active tab.
- Arrow keys move between tabs; Tab moves into the panel.
