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

# mds-tree

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

The `<mds-tree>` web component is the root container of the Magma Design System tree view, organizing a hierarchy of slotted `<mds-tree-item>` nodes into an expandable/collapsible structure. It owns no visual row of its own: it is a compound parent that configures, stacks, and propagates state to its children.

#### Semantic Behavior

- **Compound parent**: The default slot accepts only `<mds-tree-item>` elements; the tree itself renders nothing but the slot and acts as the configuration and coordination root for the hierarchy.
- **Accessibility**: The tree is a list of its items (`role="list"`, named by `label`), and the items of a branch are a list inside their item, so a screen reader announces the level and the size of every branch. It is not a `role="tree"`, which promises arrow-key navigation and leaves no room for the actions of an item: every button stays a Tab stop. The items of a closed branch are out of the tab order.
- **Depth seeding**: Its direct children are assigned `depth = 0`, which removes the branch connector lines from the first level; deeper levels are indented by their nesting.
- **Cascading `expanded`**: `expanded` on the tree, set in the markup or changed at runtime, propagates to every descendant item, opening or collapsing the whole hierarchy at once - except children marked `async`, which are left for on-demand resolution. Items added later, a branch loaded on demand, take the tree's `expanded`, `toggle`, `togglePosition`, `appearance` and `truncate` when they arrive; the items already there keep the state the user gave them.
- **Cascading `toggle` and `truncate`**: Changing the toggle icon or the truncation mode on the tree pushes the value down to all descendant items so the whole tree stays visually consistent.
- **Async branches**: When `async` is set on an item, its branch is expected to resolve its children after the click rather than expanding from pre-rendered content; such items are excluded from the bulk `expanded` cascade.

#### Properties & Visual Configurations

- **`appearance`** controls whether the depth-indicating branch decorations (connector lines and dots) are drawn: `'depth'` shows the guide lines that visualize nesting; `'none'` removes them for a flat look.
- **`actions`** governs how per-item action controls are surfaced: `'auto'` reveals them on hover, `'visible'` keeps them always shown.
- **`toggle`** selects the expand/collapse glyph for every item - `'chevron'` for a generic disclosure arrow, `'folder'` for a file-explorer metaphor; **`togglePosition`** places that glyph at the `'left'` or `'right'` of the label.

#### Other behavioral props

- **`truncate`** sets how item labels overflow: `'word'` truncates the line, `'all'` clamps to multiple lines (paired with the `--mds-tree-line-clamp` custom property), `'none'` lets text wrap freely.
- **`expanded`** is the only mutable, reflected state prop; set it on the root to open the entire tree on first render, or change it to open or close the entire tree programmatically.

## 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-tree--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 |
| --- | --- | --- | --- | --- |
| `actions` | `actions` | `"auto" \| "visible" \| undefined` | `'auto'` | Show actions on the every tree item on hover or by default. |
| `appearance` | `appearance` | `"depth" \| "none"` | `'depth'` | Specifies if the branches depth decorations are visible. |
| `async` | `async` | `boolean \| undefined` | - | **Deprecated**: Set `async` on the items that load their children on demand. Goes in the next major. Has no effect on the tree: `async` is read on each `mds-tree-item`. |
| `expanded` | `expanded` | `boolean \| undefined` | - | Specifies if the tree is expanded. |
| `label` | `label` | `string` | - | Names the tree for assistive technologies: the tree is a list of its items, and the label is what that list is called |
| `toggle` | `toggle` | `"chevron" \| "folder"` | `'chevron'` | Specifies the toggle icon of the element |
| `togglePosition` | `toggle-position` | `"left" \| "right"` | `'left'` | Specifies the toggle icon position of the element |
| `truncate` | `truncate` | `"all" \| "none" \| "word"` | `'word'` | Truncate the text of the element on one single line. |

## Slots

| Slot | Description |
| --- | --- |
| (default) | Add `mds-tree-item` element/s. |

## CSS custom properties

| Property | Description |
| --- | --- |
| `--mds-tree-line-clamp` | Sets the number of lines to show before truncating the text, it only works when attribute `truncate` is set to `all`. |

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