# chatty-tabs

API chuẩn của element chatty-tabs, sinh từ custom-elements.json của prototype trong guide.

## Key rules

- `chatty-tabs` khai báo 4 attribute, 0 property không có attribute, 1 event, 2 slot, 1 part và 2 CSS custom property.
- Import 1 module `@avada/chatty-ui/elements/tabs.js` là define `chatty-tabs`; chunk chỉ import element nó dùng. Prototype chuẩn:  trong guide.
- Đổi tên attribute, event, slot, part hay CSS custom property là đổi API: diff của custom-elements.json phải có trong 1 MR.

## Overview

A tab list over chatty-tab and chatty-tab-panel children, paired by order. Tabs and panels stay light DOM children so aria-controls and aria-labelledby resolve in one tree. Arrow Left / Right (mirrored in RTL), Home and End move between enabled tabs; `activation` automatic selects on move, manual waits for Enter, Space or a click. Class `ChattyTabs`.

### Attributes

| Name | Property | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `activation` | `activation` | `'automatic' \| 'manual'` | `'automatic'` | Automatic selects on arrow focus; manual waits for Enter or Space. |
| `segmented` | `segmented` | `boolean` | `false` | Segmented look: filled pill on a track instead of the underline. |
| `label` | `label` | `string` | `''` | Accessible name of the tab list. |
| `selected-index` | `selectedIndex` | `number` | `0` | Index of the selected tab; a user change fires change. |

### Properties

Attributes also expose the properties listed in the Property column above.

Not declared in the manifest.

### Events

| Name | Detail type | Description |
| --- | --- | --- |
| `change` | `Event` | The selected tab changed by user action; read selectedIndex. |

### Slots

| Name | Description |
| --- | --- |
| default | chatty-tab-panel children, in the order of their tabs. |
| `tab` | chatty-tab children; a chatty-tab assigns itself to this slot. |

### Parts

| Name | Description |
| --- | --- |
| `base` | The tablist row. |

### CSS custom properties

| Name | Default | Description |
| --- | --- | --- |
| `--chatty-tabs-height` | – | Tab row height. |
| `--chatty-tab-indicator` | – | Underline colour of the selected tab; its own token, so a focus-ring change leaves it alone. |

## Usage

```js
import '@avada/chatty-ui/tokens/tokens.css';
import '@avada/chatty-ui/elements/tabs.js';
import '@avada/chatty-ui/elements/tab.js';
import '@avada/chatty-ui/elements/tab-panel.js';
```

```html
<chatty-tabs label="Knowledge file tools" style="width: 100%">
  <chatty-tab>Test</chatty-tab>
  <chatty-tab>Problems</chatty-tab>
  <chatty-tab>Outline</chatty-tab>
  <chatty-tab-panel>Ask a question to test this file.</chatty-tab-panel>
  <chatty-tab-panel>No problems found.</chatty-tab-panel>
  <chatty-tab-panel>Headings of the file.</chatty-tab-panel>
</chatty-tabs>
```

## Live preview

Component thật dùng cùng story với trang component; dữ liệu mẫu nằm trong frame cục bộ.

Example (Standard) — Default: trạng thái mặc định và nội dung mẫu của element.

```html
<chatty-tabs label="Knowledge file tools" style="width: 100%">
  <chatty-tab>Test</chatty-tab>
  <chatty-tab>Problems</chatty-tab>
  <chatty-tab>Outline</chatty-tab>
  <chatty-tab-panel>Ask a question to test this file.</chatty-tab-panel>
  <chatty-tab-panel>No problems found.</chatty-tab-panel>
  <chatty-tab-panel>Headings of the file.</chatty-tab-panel>
</chatty-tabs>
```

Example (Standard) — Các variant hoặc state chính đặt cạnh nhau trong cùng ví dụ.

```html
<chatty-tabs segmented activation="manual" selected-index="1" label="Order view" style="width: 100%">
  <chatty-tab>Details</chatty-tab>
  <chatty-tab>Tracking</chatty-tab>
  <chatty-tab disabled>Returns</chatty-tab>
  <chatty-tab-panel>Items and totals.</chatty-tab-panel>
  <chatty-tab-panel>In transit, arriving Friday.</chatty-tab-panel>
  <chatty-tab-panel>No returns.</chatty-tab-panel>
</chatty-tabs>
```

## Anatomy

Số trong hình khớp bảng bên dưới. Phần chỉ hiện ở state khác được ghi Not shown; ví dụ không thêm phần tử giả.

Example (Standard) — Anatomy: một instance mặc định riêng, có khoảng trống quanh các phần được đánh số.

```html
<chatty-tabs label="Knowledge file tools" style="width: 100%">
  <chatty-tab>Test</chatty-tab>
  <chatty-tab>Problems</chatty-tab>
  <chatty-tab>Outline</chatty-tab>
  <chatty-tab-panel>Ask a question to test this file.</chatty-tab-panel>
  <chatty-tab-panel>No problems found.</chatty-tab-panel>
  <chatty-tab-panel>Headings of the file.</chatty-tab-panel>
</chatty-tabs>
```

| Part | Element | Source |
| --- | --- | --- |
| 1 | CSS part `base` | chatty-ui/custom-elements.json |

## Keyboard

| Key | Action |
| --- | --- |
| ArrowLeft / ArrowRight / Home / End | Move between tabs. |
| Enter / Space | Select a tab in manual activation mode. |

### Source

- chatty-ui/custom-elements.json
