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

# mds-pref-theme - mistakes

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

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

#### Do Not Use the Component Outside `<mds-pref>`

`<mds-pref-theme>` is a compound sub-part designed to slot inside [`<mds-pref>`](../mds-pref/AGENTS.md). As a standalone widget it still applies and persists the theme, but it leaves the panel: `<mds-pref>` can no longer forward `size` changes to it. The lock of a single-mode theme on `<mds-pref-mode>` holds either way.

```html
<!-- INCORRECT -->
<mds-pref-theme name="business" scheme="all">
  <mds-pref-theme-item label="Gestionale" name="business" scheme="all"></mds-pref-theme-item>
</mds-pref-theme>

<!-- CORRECT -->
<mds-pref>
  <mds-pref-theme name="business" scheme="all">
    <mds-pref-theme-item label="Gestionale" name="business" scheme="all"></mds-pref-theme-item>
  </mds-pref-theme>
</mds-pref>
```

#### Do Not Put Plain Text or Arbitrary HTML in the Default Slot

The default slot is reserved exclusively for `<mds-pref-theme-item>` elements. Any other content bypasses the component's internal selection management and will not trigger theme application.

```html
<!-- INCORRECT -->
<mds-pref>
  <mds-pref-theme name="business" scheme="all">
    <button>Gestionale</button>
    <span>Editoriale</span>
  </mds-pref-theme>
</mds-pref>

<!-- CORRECT -->
<mds-pref>
  <mds-pref-theme name="business" scheme="all">
    <mds-pref-theme-item label="Gestionale" name="business" scheme="all"></mds-pref-theme-item>
    <mds-pref-theme-item label="Editoriale" name="editorial" scheme="all"></mds-pref-theme-item>
  </mds-pref-theme>
</mds-pref>
```

#### Do Not Use an Invalid Theme Name

The `name` prop must match the pattern `^[a-z]+(-[a-z]+)*$` (lowercase letters and hyphens only). Any other value - including uppercase, underscores, or spaces - is ignored with a console warning when the component tries to apply the theme on `<html>`: the theme is neither applied nor stored.

```html
<!-- INCORRECT -->
<mds-pref-theme name="My Theme" scheme="all">...</mds-pref-theme>
<mds-pref-theme name="my_theme" scheme="all">...</mds-pref-theme>
<mds-pref-theme name="MyTheme" scheme="all">...</mds-pref-theme>

<!-- CORRECT -->
<mds-pref-theme name="editorial" scheme="all">...</mds-pref-theme>
```

#### Do Not Listen for the Native `change` Event

`<mds-pref-theme>` emits `mdsPrefThemeChange` - a documented custom event with a typed `{ name, scheme }` detail. Listening for the native `change` event will not fire because theme selection is handled entirely inside shadow DOM.

```html
<!-- INCORRECT -->
<script>
  document.querySelector('mds-pref-theme').addEventListener('change', (e) => {
    console.log(e.target.value); // undefined - wrong event, wrong detail shape
  });
</script>

<!-- CORRECT -->
<script>
  document.querySelector('mds-pref-theme').addEventListener('mdsPrefThemeChange', (e) => {
    console.log(e.detail.name, e.detail.scheme);
  });
</script>
```

#### Do Not Give the Parent and the Child Different Sizes

`<mds-pref>` forwards its own `size` to all `mds-pref-*` children, on load and when it changes, and overwrites theirs: a `size` on `<mds-pref-theme>` that differs from the parent's is never shown. Set the size on the parent only.

```html
<!-- INCORRECT -->
<mds-pref size="sm">
  <mds-pref-theme size="md" name="default" scheme="all">
    <mds-pref-theme-item label="Gestionale" name="business" scheme="all"></mds-pref-theme-item>
  </mds-pref-theme>
</mds-pref>

<!-- CORRECT -->
<mds-pref size="sm">
  <mds-pref-theme name="business" scheme="all">
    <mds-pref-theme-item label="Gestionale" name="business" scheme="all"></mds-pref-theme-item>
  </mds-pref-theme>
</mds-pref>
```
