<!--
  GENERATED FILE - do not edit by hand.
  Source of truth: src/components/mds-tab-bar/usage/ in the magma monorepo.
-->

# mds-tab-bar - mistakes

> The API of this component: [`AGENTS.md`](AGENTS.md).

Common incorrect uses of `<mds-tab-bar>`. Each entry pairs the wrong form with the right one and a one-line reason. System-wide rules (boolean-as-string, shadow piercing, Tailwind color utilities, raw native event listening) live in [`agents/mistakes.md`](../../../../agents/mistakes.md) - they apply here too but are not repeated.

#### Do Not Place HTML Elements or Text Directly in the Bar's Default Slot

`<mds-tab-bar>` only coordinates `<mds-tab-bar-item>` children; arbitrary HTML or text in its slot breaks the mutual-exclusion logic and the change event.

```html
<!-- INCORRECT -->
<mds-tab-bar>
  <button>Home</button>
  <a href="/cerca">Cerca</a>
</mds-tab-bar>

<!-- CORRECT -->
<mds-tab-bar>
  <mds-tab-bar-item icon="mi/baseline/home" label="Home" selected></mds-tab-bar-item>
  <mds-tab-bar-item icon="mi/baseline/search" label="Cerca"></mds-tab-bar-item>
</mds-tab-bar>
```

#### Do Not Use the Deprecated Default Slot for an Item's Text

Setting an item's text via the default slot is deprecated. Slotted text is read into `label`, and nested HTML is stripped with a console warning - use the `label` prop for the text and the `icon` prop for the glyph.

```html
<!-- INCORRECT -->
<mds-tab-bar-item icon="mi/baseline/inbox">Messaggi</mds-tab-bar-item>
<mds-tab-bar-item>
  <span class="bold">Messaggi</span>
  <small>(3)</small>
</mds-tab-bar-item>

<!-- CORRECT -->
<mds-tab-bar-item icon="mi/baseline/inbox" label="Messaggi"></mds-tab-bar-item>
```

#### Do Not Slot `<mds-icon>` to Add an Icon

The item's `icon` prop renders the glyph through the shared icon service and positions it correctly above the label. Slotting `<mds-icon>` puts it in the deprecated default slot, where it is misaligned or stripped.

```html
<!-- INCORRECT -->
<mds-tab-bar-item>
  <mds-icon name="mi/baseline/home"></mds-icon>
  Home
</mds-tab-bar-item>

<!-- CORRECT -->
<mds-tab-bar-item icon="mi/baseline/home" label="Home"></mds-tab-bar-item>
```

#### Do Not Set `selected="false"` to Deselect an Item

`selected` is a boolean attribute. The item happens to style `selected="false"` as unselected, but the attribute stays on the element and contradicts the state for attribute selectors and checks. Remove the attribute entirely to deselect an item, or let the parent coordinate selection automatically.

```html
<!-- INCORRECT -->
<mds-tab-bar-item icon="mi/baseline/home" label="Home" selected="false"></mds-tab-bar-item>

<!-- CORRECT -->
<mds-tab-bar-item icon="mi/baseline/home" label="Home"></mds-tab-bar-item>
```

#### Do Not Listen for the Item's Internal Event on the Bar's Children

`mdsTabBarItemSelect` is the item-level event `<mds-tab-bar>` coordinates on: its `detail` is the item's `id`, the one you gave it or the `mds-tab-bar-item-<index>` the bar gives an item without one. To react to selection changes from outside, listen for `mdsTabBarChange` on the parent instead, whose `detail.index` is the position of the selected item.

```html
<!-- INCORRECT -->
<script>
  document.querySelector('mds-tab-bar-item').addEventListener('mdsTabBarItemSelect', handler);
</script>

<!-- CORRECT -->
<script>
  document.querySelector('mds-tab-bar').addEventListener('mdsTabBarChange', (e) => {
    handler(e.detail.index);
  });
</script>
```

#### Do Not Style Items by Piercing Shadow DOM

The only supported customization surface is the two public `--mds-tab-bar-item-*` CSS custom properties, `--mds-tab-bar-item-background` and `--mds-tab-bar-item-color` (the icon follows the text colour). Targeting internal nodes via `::part()`, `>>>`, or undocumented class names couples your code to the Shadow DOM implementation and will break on minor releases.

```css
/* INCORRECT */
mds-tab-bar-item >>> mds-icon {
  fill: hotpink;
}

/* CORRECT */
mds-tab-bar mds-tab-bar-item {
  --mds-tab-bar-item-color: rgb(var(--magma-text-muted));
}
```
