> Part of the [Tangram component index](/docs/components/index.md). Use the index to find other components.

# Tab (Tangram 2)

Use `<tg2-tab>` only inside [`<tg2-tabs>`](/docs/components/tg2-tabs/tg2-tabs.md). The content of `<tg2-tab>` is the panel.

- `label` sets the tab text.
- `iconLeft` and `iconRight` take a Tangram icon name. The icon is 16px at the `small` and `medium` tabs sizes, and 24px at `large`.
- A `disabled` tab is not in the `Tab` and arrow-key sequences. `Home` and `End` skip it. A click does not select it.
- The `active` signal is `true` while the tab is selected. Use it with `@defer` to load a large panel only when its tab opens.

```html
<tg2-tabs ariaLabel="Listing">
    <tg2-tab
        label="Details"
        iconLeft="star">
        Panel content
    </tg2-tab>
    <tg2-tab
        label="Reviews"
        disabled>
        Unavailable
    </tg2-tab>
</tg2-tabs>
```

<!-- generated:api:start -->
<!-- Generated from tg2-tab.component.ts by npm run docs:components. Do not edit by hand. -->

## API

Selector: `tg2-tab`. Import `Tg2TabComponent` from `@trademe/tangram`.

Experimental: the API can change in a minor release.

### Inputs

- `label`: `string`. Required.
- `iconLeft`: `TangramIconKind | undefined`.
- `iconRight`: `TangramIconKind | undefined`.
- `disabled`: `boolean`. Default `false`.

### Content slots

- Default content

<!-- generated:api:end -->

# Tabs (Tangram 2)

Put one or more [`<tg2-tab>`](/docs/components/tg2-tabs/tg2-tab.md) elements inside `<tg2-tabs>`. Put the panel content of each tab directly inside its `<tg2-tab>`. There is no heading element and no content wrapper element.

- Give every tablist an accessible name with `ariaLabel`. You must do this when a page has more than one set of tabs.
- Bind `[(selected)]` to the zero-based index of the open tab.
- On a page that still has the old Tangram design, set `theme="tg-light"`.

```html
<tg2-tabs
    ariaLabel="Product details"
    [(selected)]="selectedIndex">
    <tg2-tab label="Details">Panel one content</tg2-tab>
    <tg2-tab label="Reviews">Panel two content</tg2-tab>
    <tg2-tab
        label="Shipping"
        disabled>
        Panel three content
    </tg2-tab>
</tg2-tabs>
```

If `selected` is below 0 or past the last tab, the component selects the first or last tab. If the selected tab is disabled, the component selects the first enabled tab. It then emits the corrected index through `selectedChange`, so a two-way binding always matches the screen.

## Sizes

- `small`: 14px text, 32px tall. This is the default under `tg2-light` and `tg2-dark`.
- `medium`: 16px text, 40px tall.
- `large`: 18px text, 48px tall. This is the default under `tg-light` and `tg-dark`.

The heights match `tg2Button` at the same size.

## Overflow

When the tabs are wider than their container, the strip scrolls horizontally and fades at the clipped edge.

Arrow keys, clicks and a bound `selected` value scroll the strip to keep the focused or selected tab in view. The component never scrolls the page.

## Keyboard navigation

- `Tab` / `Shift+Tab`: move through each tab in order, then into the selected panel.
- `ArrowLeft` / `ArrowRight`: move focus between tabs. Focus wraps at the ends. The selected tab does not change.
- `Home` / `End`: move focus to the first or last enabled tab.
- `Enter` / `Space`: select the focused tab.

Activation is manual. When an arrow key moves focus to a tab, the tab shows its focus ring, but the panel does not change. The keyboard skips disabled tabs.

## Server-side rendering and hydration

By default, the server renders the content of every tab. The user sees only the selected panel, but search engines can index all panels.

For a large component, gate it on the `active` signal of its tab with `@defer`. The server sends the placeholder. The browser loads the component when its tab is active, also when it is the first tab.

<!-- prettier-ignore -->
```html
<tg2-tabs [(selected)]="selectedTab">
    <tg2-tab label="Overview">
        <app-listing-overview />
    </tg2-tab>
    <tg2-tab #historyTab label="Price history">
        @defer (when historyTab.active()) {
            <app-price-history-chart />
        } @placeholder {
            <p>Chart loading…</p>
        }
    </tg2-tab>
</tg2-tabs>
```

There is no `lazy` input. Use `@defer` in your template.

## Dark themes

Do not use `theme="tg2-dark"` or `"tg-dark"`. Design has not reviewed dark mode. It is a work in progress.

<!-- generated:api:start -->
<!-- Generated from tg2-tabs.component.ts by npm run docs:components. Do not edit by hand. -->

## API

Selector: `tg2-tabs`. Import `Tg2TabsComponent` from `@trademe/tangram`.

Experimental: the API can change in a minor release.

### Inputs

- `ariaLabel`: `string | undefined`.
- `selected`: `number`. Two-way: `[(selected)]`. Default `0`.
- `size`: `small` | `medium` | `large`.
- `theme`: `tg2-light` | `tg2-dark` | `tg-light` | `tg-dark`. Default `tg2-light`.

### Outputs

- `selectedChange`: `number`.

<!-- generated:api:end -->
