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

# mds-chip - mistakes

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

Common incorrect uses of `<mds-chip>`. 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 Use a Clickable Chip Without `clickable` or `selectable`

Without `clickable`, the chip has no `role`, no focus management, and no keyboard activation. Listening for click events on a static chip is a silent accessibility failure.

```html
<!-- INCORRECT -->
<mds-chip label="Apri" variant="primary" onclick="doSomething()"></mds-chip>

<!-- CORRECT -->
<mds-chip label="Apri" clickable variant="primary"></mds-chip>
<script>
  document.querySelector('mds-chip').addEventListener('mdsChipClickLabel', doSomething);
</script>
```

#### Do Not Use `selected` Without `selectable`

`selected` only has visual and semantic meaning when `selectable` is also set. On a non-selectable chip the attribute renders the selected style but the selection can never be toggled and no event fires, misleading users.

```html
<!-- INCORRECT -->
<mds-chip label="Attivo" selected variant="success"></mds-chip>

<!-- CORRECT -->
<mds-chip label="Attivo" selectable selected variant="success"></mds-chip>
```

#### Do Not Apply `tone` Values Outside the Minimal Ladder

`mds-chip` accepts only `ToneMinimalVariantType`: `strong` and `weak`. Passing `outline`, `text`, or `box` is invalid: no style matches it, so the chip silently loses its variant colors.

```html
<!-- INCORRECT -->
<mds-chip label="Categoria" tone="outline" variant="primary"></mds-chip>
<mds-chip label="Categoria" tone="text" variant="primary"></mds-chip>

<!-- CORRECT -->
<mds-chip label="Categoria" tone="weak" variant="primary"></mds-chip>
<mds-chip label="Categoria" tone="strong" variant="primary"></mds-chip>
```

#### Do Not Slot Content Into the Chip

`<mds-chip>` has no default or named slots - all content is driven by props (`label`, `icon`, `swatch`, `deletable`). Slotting HTML children is ignored by the Shadow DOM.

```html
<!-- INCORRECT -->
<mds-chip>
  <span>Etichetta</span>
  <mds-icon name="mi/baseline/close"></mds-icon>
</mds-chip>

<!-- CORRECT -->
<mds-chip
  label="Etichetta"
  icon="mi/baseline/pets"
  deletable
  variant="primary"
></mds-chip>
```

#### Do Not Draw a Colour Through the Icon

A circle icon painted with the colour, or the markup of an `<svg>` given to `icon`, sits on the disc of the icon, has no ring to keep a colour as light or as dark as the chip visible, and leans on custom properties that are not public. Give the colour to `swatch`.

```html
<!-- INCORRECT -->
<mds-chip label="fireclay" icon="mdi/circle" style="--mds-chip-icon-color: #a89586"></mds-chip>

<!-- CORRECT -->
<mds-chip label="fireclay" swatch="#a89586"></mds-chip>
```

#### Do Not Say a State With a Swatch

The swatch draws its colour as given: a status painted there does not follow the mode, the named theme or the contrast preference as a variant does, and, hidden from assistive technologies, it adds nothing a screen reader hears. Say a status with `variant` and an icon; keep `swatch` for a colour the label names.

```html
<!-- INCORRECT -->
<mds-chip label="Errore" swatch="#d32f2f"></mds-chip>

<!-- CORRECT -->
<mds-chip label="Errore" icon="mi/baseline/error" variant="error" tone="strong"></mds-chip>
```

#### Do Not Pierce Shadow DOM to Style the Delete Button

The inner `mds-button` used for the delete affordance is a Shadow DOM implementation detail with no styling API of its own: targeting it with `>>>` or undocumented `::part()` names will break on minor releases. Restyle the chip and its leading icon through the public `--mds-chip-*` properties.

```css
/* INCORRECT */
mds-chip >>> .button-delete {
  color: red;
}

/* CORRECT */
mds-chip {
  --mds-chip-icon-background: rgb(var(--magma-danger-emphasis));
}
```

#### Do Not Forget to Remove `await`-Pattern Analogue: Removing `selected` by Setting It to `false`

With `selected="false"` the component reads the prop as `false` and drops the attribute when it renders, but until then the attribute is in the DOM and attribute selectors (`mds-chip[selected]`) match it. Remove the attribute; from JavaScript both `false` and `undefined` deselect the chip (the component turns `false` into `undefined` and drops the attribute).

```html
<!-- INCORRECT -->
<mds-chip label="Filtro" selectable selected="false" variant="primary"></mds-chip>

<!-- CORRECT -->
<mds-chip label="Filtro" selectable variant="primary"></mds-chip>
```

#### Do Not Use `<mds-chip>` as a Navigation Link

`<mds-chip>` has no `href` prop. Wrapping it in an `<a>` creates a nested interactive element, breaks keyboard semantics, and fails accessibility audits. Use [`mds-button`](../mds-button/AGENTS.md) with `href` instead.

```html
<!-- INCORRECT -->
<a href="/categoria/sport">
  <mds-chip label="Sport" variant="primary"></mds-chip>
</a>

<!-- CORRECT -->
<mds-button
  label="Sport"
  href="/categoria/sport"
  variant="primary"
  tone="weak"
></mds-button>
```
