<!--
  GENERATED FILE - do not edit by hand.
  Source of truth: src/components/mds-tab/ in the magma monorepo (usage/*.md and the
  component's JSDoc). Regenerated on every stencil build (scripts/component-docs.ts).
-->

# mds-tab

> `@maggioli-design-system/magma` 2.15.0. Shadow DOM: style it only through the public CSS custom properties and the parts below.

The `<mds-tab>` web component is the compound container that orchestrates a tabbed navigation in the Magma Design System. It is the parent wrapper around a set of `<mds-tab-item>` triggers and, when the component shows the content itself, their content panels, providing the ARIA `tablist` structure, selection state, scrolling and the animated selection indicator.

#### Semantic Behavior

- **Compound parent**: Expects `<mds-tab-item>` elements in the default slot; each panel in the named `content` slot is wired up automatically and paired by document order; a panel past the last item has no tab to open it, so it stays hidden and the component logs a console warning. The panels are optional: without them the component shows the strip alone, and the page shows the content, driven by `mdsTabChange` or by navigation.
- **Navigation strip**: When every item has `href`, the items are links (announced as such, the selected one as current) and the strip is no longer a `tablist`: the browser follows the links, in a new tab on a modifier or middle click, and the strip keeps the selected item highlighted. A client-side router cancels the click on the item with `preventDefault()` and routes; a modifier click leaves the selection alone.
- **Selection ownership**: The active tab is whichever `<mds-tab-item>` carries `selected`; the parent flips `selected` across siblings, shows the corresponding content panel and hides the rest.
- **Change event**: Emits `mdsTabChange` with the selected item's index (`id`) and `value` whenever the active child changes.
- **Focus restoration**: After a keyboard activation it re-focuses the selected item's button, so the user does not have to re-locate the tab. An item selected from code (`selected` set by the page) leaves the focus where it is.
- **Auto-scroll into view**: On selection or child focus, the active tab is scrolled to the center of its strip.
- **Overflow tracking**: When `overflow` is enabled, left/right inset shadows appear while the tabs overflow their container.
- **Size propagation**: The parent `size` is pushed down onto every nested `<mds-tab-item>`, so children should not be sized individually.

#### Properties & Visual Configurations

- **`direction`** chooses whether the tab strip is laid out `'horizontal'` (default) or `'vertical'`.
- **`animation`** governs the transition between active items: `'slide'` (default) renders the moving slider indicator, while `'fade'` cross-fades without the slider. The slider slides only when the selection changes: on load, and when the strip is shown again after being hidden, it is already under the selected tab.
- **`fill`** makes the tab strip stretch to occupy the full available width rather than hugging its content.
- **`overflow`** enables the inset-shadow affordance that signals more tabs exist beyond the visible edges; **`scrollbar`** instead exposes the native horizontal scrollbar for accessibility.

#### Other behavioral props

- **`size`** sets the scale (`'sm'` / `'md'`) for the whole group and is forwarded to the child items; it is the only way to size the tabs consistently.

## Read next

- [`examples.md`](examples.md) - correct usage, from the most common case
- [`mistakes.md`](mistakes.md) - the wrong forms, each with the right one
- [Storybook](https://magma-design-system.github.io/magma/storybook/?path=/docs/ui-tab--docs) - the live examples, in the published Storybook of `main`
- [`conventions.md`](../../../../agents/conventions.md), [`variants.md`](../../../../agents/variants.md), [`mistakes.md`](../../../../agents/mistakes.md) - the rules shared by every component

## Props

| Prop | Attribute | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `animation` | `animation` | `"fade" \| "slide" \| undefined` | `'slide'` | Sets the animation type of the selection transition between `mds-tab-item` elements |
| `direction` | `direction` | `"horizontal" \| "vertical" \| undefined` | `'horizontal'` | Sets if the component distributes item vertically or horzontally |
| `fill` | `fill` | `boolean \| undefined` | - | Sets if the tab area should fill the entire width |
| `overflow` | `overflow` | `boolean \| undefined` | - | Sets if the tab area should show an inset shadow when the tabs overflows it's container |
| `scrollbar` | `scrollbar` | `boolean \| undefined` | - | Shows the horizontal scrollbar to maximize accessibility |
| `size` | `size` | `"md" \| "sm" \| undefined` | - | Sets the size of the component items nested inside it |

## Events

| Event | Detail | Description |
| --- | --- | --- |
| `mdsTabChange` | `MdsTabEventDetail` | Emits when a children is changed |

## Slots

| Slot | Description |
| --- | --- |
| (default) | Add `mds-tab-item` element/s. |
| `content` | Add `HTML elements` or `components`, one per mds-tab-item added; or none, when the items are links (`href`) to other pages or places and the page, not the component, shows the content. |

## Parts

| Part | Description |
| --- | --- |
| `contents` | Selects the container of the tabbed contents elements. |
| `slider` | Selects the slider element which is visible when attribute `animation` is set to `slide`. |
| `tabs` | Selects the container of `mds-tab-item` list elements. |

## CSS custom properties

| Property | Description |
| --- | --- |
| `--mds-tab-direction-vertical-columns` | Defines the column layout for vertical tabs. |
| `--mds-tab-tabs-background` | Background color of the tabs container. |
| `--mds-tab-tabs-wrapper-margin` | Margin for the tabs wrapper. |
| `--mds-tab-tabs-wrapper-shadow` | Shadow for the tabs wrapper. |

Only these are public. Its other 26 are internal: they may change in any release, do not set them.

## Dependencies

Used by: `mds-input-date-range`, `mds-input-upload`, `mds-pref-animation`, `mds-pref-consumption`, `mds-pref-contrast`, `mds-pref-language`, `mds-pref-mode`, `mds-pref-theme`.
