# Tab List

## Usage

Import `TabList` and `Tab` from their dedicated entry and control selection with `v-model:value`.

```vue
<script setup lang="ts">
import { Tab, TabList } from '@astryx-vue/core/TabList'
import { ref } from 'vue'

const value = ref('overview')
</script>

<template>
  <TabList v-model:value="value">
    <Tab value="overview">
      Overview
    </Tab>
    <Tab value="props">
      Props
    </Tab>
    <Tab value="examples">
      Examples
    </Tab>
  </TabList>
</template>
```

### Anatomy

- **Left Content**: Most important area; hugs content width.
- **Center-Fill Content**: Stretches to fill available space.
- **Right Content**: Hugs content width.

## Best practices

| Guidance | Practice |
| --- | --- |
| Recommended | Leave `role` unset for a navigation landmark that marks the current tab with `aria-current="true"`. Set `role="tablist"` to opt into the tabs pattern, with `role="tab"` and `aria-selected`. Tabs wider than the strip scroll sideways by default. |
| Recommended | Give each `Tab` a unique `value` for selection and keyboard navigation. |
| Recommended | Use `disabled` for unavailable tabs; keyboard navigation skips them automatically. |
| Don't | Put too many tabs in a single strip; consider scrolling or reorganizing content when it overflows. |
| Don't | Use TabList for page-level navigation; Breadcrumbs or Link are better for wayfinding. |

## Examples

### Fill layout

With layout set to fill, the tabs share the width of the row and a divider sits under the list.

```vue
<script setup lang="ts">
import { Tab, TabList } from '@astryx-vue/core/TabList'
import { ref } from 'vue'

const value = ref('home')
</script>

<template>
  <div class="tab-list-preview__width">
    <TabList v-model:value="value" has-divider layout="fill">
      <Tab value="home">
        Home
      </Tab>
      <Tab value="projects">
        Projects
      </Tab>
      <Tab value="settings">
        Settings
      </Tab>
    </TabList>
  </div>
</template>
```

### With actions

Tabs stay on the left and the filter and create buttons sit on the right. With a divider, the buttons use the same size as the tabs.

```vue
<script setup lang="ts">
import { Button } from '@astryx-vue/core/Button'
import { Tab, TabList } from '@astryx-vue/core/TabList'
import { ref } from 'vue'

const value = ref('all')
</script>

<template>
  <TabList v-model:value="value" class="tab-list-preview__actions" has-divider size="lg">
    <Tab value="all">
      All items
    </Tab>
    <Tab value="active">
      Active
    </Tab>
    <Tab value="archived">
      Archived
    </Tab>
    <div class="tab-list-preview__end">
      <Button label="Filter" variant="ghost" size="lg" is-icon-only>
        <template #icon>
          <span class="css-icon css-icon--sm i-carbon-filter" />
        </template>
      </Button>
      <Button label="New item" variant="primary" size="lg">
        <template #icon>
          <span class="css-icon css-icon--sm i-carbon-add" />
        </template>
      </Button>
    </div>
  </TabList>
</template>
```

### With badge

A badge after the label. Error is for a count that needs attention; neutral is for an ordinary count.

```vue
<script setup lang="ts">
import { Badge } from '@astryx-vue/core/Badge'
import { Tab, TabList } from '@astryx-vue/core/TabList'
import { ref } from 'vue'

const value = ref('inbox')
</script>

<template>
  <TabList v-model:value="value">
    <Tab value="inbox">
      <template #endContent>
        <Badge variant="error">
          5
        </Badge>
      </template>
      Inbox
    </Tab>
    <Tab value="sent">
      Sent
    </Tab>
    <Tab value="drafts">
      <template #endContent>
        <Badge variant="neutral">
          2
        </Badge>
      </template>
      Drafts
    </Tab>
  </TabList>
</template>
```

### With icons

An icon before the label, so each tab is recognizable before the word is read.

```vue
<script setup lang="ts">
import { Tab, TabList } from '@astryx-vue/core/TabList'
import { ref } from 'vue'

const value = ref('home')
</script>

<template>
  <TabList v-model:value="value">
    <Tab value="home">
      <template #icon>
        <span class="css-icon css-icon--sm i-carbon-home" />
      </template>
      Home
    </Tab>
    <Tab value="settings">
      <template #icon>
        <span class="css-icon css-icon--sm i-carbon-settings" />
      </template>
      Settings
    </Tab>
  </TabList>
</template>
```

### Scrolling strip

When the tabs are wider than the strip, it scrolls horizontally. The hidden edge fades, arrows appear for pointers that can hover, and the selected tab is scrolled into view.

```vue
<script setup lang="ts">
import { Tab, TabList } from '@astryx-vue/core/TabList'
import { ref } from 'vue'

const sections = [
  'Overview',
  'Activity',
  'Members',
  'Projects',
  'Milestones',
  'Releases',
  'Integrations',
  'Billing',
  'Security',
  'Audit log',
  'Settings',
]
const value = ref('Releases')
</script>

<template>
  <div style="max-width: 360px; width: 100%">
    <TabList v-model:value="value" has-divider>
      <Tab v-for="section in sections" :key="section" :value="section">
        {{ section }}
      </Tab>
    </TabList>
  </div>
</template>
```

### With overflow menu

Tabs that do not fit inline go into a TabMenu. Choosing one makes it the selected tab.

```vue
<script setup lang="ts">
import { Tab, TabList, TabMenu } from '@astryx-vue/core/TabList'
import { ref } from 'vue'

const value = ref('home')
</script>

<template>
  <TabList v-model:value="value">
    <Tab value="home">
      Home
    </Tab>
    <Tab value="projects">
      Projects
    </Tab>
    <TabMenu
      label="More"
      :options="[
        { value: 'analytics', label: 'Analytics' },
        { value: 'reports', label: 'Reports' },
        { value: 'billing', label: 'Billing' },
      ]"
    />
  </TabList>
</template>
```

### With status dot

A status dot after the label shows whether an environment is healthy.

```vue
<script setup lang="ts">
import { StatusDot } from '@astryx-vue/core/StatusDot'
import { Tab, TabList } from '@astryx-vue/core/TabList'
import { ref } from 'vue'

const value = ref('production')
</script>

<template>
  <TabList v-model:value="value">
    <Tab value="production">
      <template #endContent>
        <StatusDot label="Healthy" variant="success" />
      </template>
      Production
    </Tab>
    <Tab value="staging">
      <template #endContent>
        <StatusDot label="Degraded" variant="warning" />
      </template>
      Staging
    </Tab>
    <Tab value="development">
      Development
    </Tab>
  </TabList>
</template>
```

## TabList Props

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `value` | `string` | - | Currently selected tab value. Supports `v-model:value`. |
| `size` | `TabListSize` | `'md'` | Tab size. Optional: `sm`, `md`, `lg`. |
| `layout` | `TabListLayout` | `'hug'` | Tab layout. Optional: `hug`, `fill`. `hug` sizes to content, `fill` distributes evenly. |
| `hasDivider` | `boolean` | `false` | Whether to show a bottom divider. |
| `overflow` | `'auto' \| 'scroll' \| 'visible'` | `'auto'` | What happens when the tabs are wider than the strip. `auto` and `scroll` scroll sideways, fade the hidden edge, and offer page arrows. `visible` does not scroll. A selected tab that is out of view scrolls back into view immediately. |
| `role` | `string` | - | ARIA role of the strip. `tablist` selects the tabs pattern: tabs get `role="tab"` with `aria-selected`, and each tab points at its panel through `panelId`. Left unset, the strip is a navigation landmark that marks the current tab with `aria-current` and renders a tab with `href` as a link. Any other value is passed through to the element. |

## TabList Events

| Name | Description |
| --- | --- |
| `update:value` | Emitted when the selected value changes. |
| `change` | Emitted when the selected value changes. |

## TabList Slots

| Name | Description |
| --- | --- |
| `default` | List of `Tab` elements. |

## Tab Props

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `value` | `string` | - | Unique tab value. |
| `label` | `string` | - | Visible text of the tab, also used as the accessible name when `isLabelHidden` is set. The default slot wins when both are given. |
| `href` | `string` | - | URL to navigate to. Outside the tabs pattern the tab renders as a link; inside a `role="tablist"` strip it is ignored. |
| `as` | `string \| Component` | `'a'` | Link root component, such as a router link. Only applies when `href` is given and the strip is not a tablist. |
| `isLabelHidden` | `boolean` | `false` | Visually hides the label so only the icon and end content show. The label stays available through `aria-label`. |
| `panelId` | `string` | - | ID of the controlled panel for `aria-controls`. |
| `disabled` | `boolean` | `false` | Whether the tab is disabled. |

## Tab Slots

| Name | Description |
| --- | --- |
| `default` | Tab label text. |
| `icon` | Icon shown while the tab is not selected. |
| `selectedIcon` | Icon shown while the tab is selected. Falls back to `icon`. |
| `endContent` | Content after the label, such as a badge count or a status dot. |

## Accessibility

### Tab label

- Criterion: 1.4.3 Contrast (Minimum)
- Check: 4.5:1
- States: Rest, Hover, Pointer down, Selected

Each label must have at least 4.5:1 contrast with the tab surface behind it. For Hover and Pointer down, measure the final background after the overlay layer is applied.
