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

# mds-table

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

The `<mds-table>` web component is the root container of the Magma Design System tabular data system. It wraps a native `<table>` and orchestrates a family of compound children (`mds-table-header`, `mds-table-body`, `mds-table-footer`, `mds-table-row`, `mds-table-cell`), propagating interaction, selection, and overflow state down to them.

#### Semantic Behavior

- **Compound parent**: The default slot must hold `mds-table-header` / `mds-table-body` / `mds-table-footer`; `<mds-table>` pushes its own `interactive` and `selectable` state onto every `mds-table-row` and the header/body. It is not used standalone.
- **Selection model**: When `selectable` is set, rows expose a checkbox; the component aggregates the selected rows, mirrors the count to the header's tristate control, and flags that a selection exists so it is visible to CSS and consumers.
- **Selection event**: Emits `mdsTableSelectionChange` (bubbles, composed) carrying `{ rows }`, an array of `{ index, value }` for every selected row. It follows every change of a row's `selected`, from its checkbox or from code, and `selectAll(select?)`; changes made together are announced once. Rows that arrive already `selected` (in the markup on load, or rendered later) are counted but not announced, as a native control fires no `change` for its initial value. Both are no-ops unless `selectable` is true.
- **Live children**: Rows added or removed at runtime are re-wired with the table's interactive and selectable state and counted in the selection, so dynamically added rows behave consistently.
- **Action overflow**: When rows carry a `[slot="action"]`, rows flip into an overlaid-action mode once content exceeds the visible width. Rows and actions added after the first load are followed too: the header gains its Actions column and the new rows the overlay.
- **Localization**: Resolves its display language from the page (`<html lang>`: `el`/`en`/`es`/`it`, otherwise `en`) for the batch-actions label.

#### Properties & Visual Configurations

- **`interactive`** highlights rows on mouseover; choose it for tables whose rows are clickable or navigable, not for purely static read-only data.
- **`selectable`** turns on per-row checkbox selection and the aggregated header/batch-actions machinery; without it the selection methods and the `batch-action` slot are inert.
- **`selection`** is a read-back flag that becomes true while at least one row is selected - it is managed internally, not something callers normally set.
- **`sorting`** says who orders the rows when a sortable `mds-table-header-cell` changes direction. `internal` (default) moves the rows in the DOM; `external` leaves them where they are, so the application listens to `mdsTableHeaderCellSort` and renders the rows in the order asked. Choose `external` whenever the table shows one page of a larger set (with `mds-paginator`) or the order comes from a back end: sorting the DOM would only sort the page on screen.

#### Other behavioral props

- **`batch-action` slot** holds `mds-button` element/s; its bar renders only when `selectable` is on and at least one batch action is slotted, surfacing a live count badge of the current selection.

## 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/layout-table--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 |
| --- | --- | --- | --- | --- |
| `interactive` | `interactive` | `boolean \| undefined` | - | Specifies if the table rows are higlighted on mouseover event |
| `selectable` | `selectable` | `boolean \| undefined` | - | Specifies if the table rows are selectable by a checkbox |
| `selection` | `selection` | `boolean \| undefined` | - | Indicates whether row selection is currently active in the table. |
| `sorting` | `sorting` | `"external" \| "internal" \| undefined` | `'internal'` | Specifies who sorts the rows when a sortable header cell changes direction: `internal` moves them in the DOM, `external` leaves them to the application, which listens to `mdsTableHeaderCellSort` and renders the rows in the order asked (a table that shows one page of a larger set) |

## Events

| Event | Detail | Description |
| --- | --- | --- |
| `mdsTableSelectionChange` | `MdsTableSelectionEventDetail` | Emits when the selection of a `selectable` table changes, with the index and the value of each selected row. It announces changes only: not the rows that arrive already `selected` (in the markup on load, or rendered later), which the table counts all the same, as a native control fires no `change` for its initial value |

## Methods

| Method | Signature | Description |
| --- | --- | --- |
| `selectAll` | `selectAll(select?: boolean) => Promise<void>` | Selects all elements or none, works only if `selectable` is true. |
| `updateActions` | `updateActions() => Promise<void>` | `internal` Reads again whether the rows have `slot="action"` content: shows or hides the Actions column of the header and wires the overlay of the actions. Runs when rows come and go, and mds-table-row calls it when the content of its `action` slot changes. |
| `updateSelection` | `updateSelection() => Promise<void>` | `internal` Updates the selection data event and emits it, it's used to avoid add event listener to the dom and lower performance, works only if `selectable` is true. |

## Slots

| Slot | Description |
| --- | --- |
| (default) | Put `mds-table-header`, `mds-table-body`, `mds-table-footer` element/s. |
| `batch-action` | Put `mds-button` element/s. |

## Parts

| Part | Description |
| --- | --- |
| `batch-actions` | Selects the element which wraps the batch actions |
| `batch-actions-wrapper` | The bar of the batch actions, shown while the table is `selectable` and has `batch-action` content |
| `table` | Selects the table element |
| `table-wrapper` | Selects the element which wraps the table |

## CSS custom properties

| Property | Description |
| --- | --- |
| `--mds-table-background` | Default background color of the table. |
| `--mds-table-cell-padding` | Padding inside table cells. |
| `--mds-table-color` | Default text color of the table. |

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

## Dependencies

Uses: `mds-text`, `mds-badge`.
