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

# mds-pref - mistakes

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

Common incorrect uses of `<mds-pref>`. 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 Non-Pref Children in the Default Slot

The default slot accepts only `mds-pref-animation`, `mds-pref-consumption`, `mds-pref-contrast`, `mds-pref-language`, `mds-pref-mode` and `mds-pref-theme` children. Other elements are outside the documented content: they render as extra rows of the panel and take part in no coordination.

```html
<!-- INCORRECT -->
<mds-pref>
  <div class="custom-section">Tema</div>
  <mds-pref-mode></mds-pref-mode>
</mds-pref>

<!-- CORRECT -->
<mds-pref>
  <mds-pref-mode></mds-pref-mode>
</mds-pref>
```

#### Do Not Use `mds-pref-*` Children Outside `<mds-pref>`

Each control applies and stores its own preference, but the coordination between the controls of a panel lives in the parent: only the parent forwards `size` changes and sets the `data-magma-pref` flag that turns off the fallback to the OS preferences. Group the controls of a panel in `<mds-pref>`.

```html
<!-- INCORRECT -->
<mds-pref-mode></mds-pref-mode>
<mds-pref-theme>
  <mds-pref-theme-item name="default"></mds-pref-theme-item>
  <mds-pref-theme-item name="cool"></mds-pref-theme-item>
</mds-pref-theme>

<!-- CORRECT -->
<mds-pref>
  <mds-pref-mode></mds-pref-mode>
  <mds-pref-theme>
    <mds-pref-theme-item name="default"></mds-pref-theme-item>
    <mds-pref-theme-item name="cool"></mds-pref-theme-item>
  </mds-pref-theme>
</mds-pref>
```

#### Do Not Set `controller="false"` to Turn Off Controller Mode

`controller` is a boolean attribute, and a false boolean is an absent attribute ([`agents/conventions.md`](../../../../agents/conventions.md)). The runtime parses the string `"false"` as `false`, so the panel shows, but the attribute is still on the element until the first render, so `[controller]` attribute selectors (the one that hides the panel included) and any code that reads the attribute see it set. Remove the attribute entirely to switch back to visible mode.

```html
<!-- INCORRECT -->
<mds-pref controller="false">
  <mds-pref-mode></mds-pref-mode>
</mds-pref>

<!-- CORRECT -->
<mds-pref>
  <mds-pref-mode></mds-pref-mode>
</mds-pref>
```

#### Do Not Listen for the Native `change` Event to Detect Preference Changes

The controls fire no native `change` event. Use the documented `mdsPrefChange` event emitted by each `mds-pref-*` child: it fires once per change, not on page load, and carries only the `preference` name in `detail`, so read the new value from the child.

```html
<!-- INCORRECT -->
<script>
  document.querySelector('mds-pref').addEventListener('change', (e) => {
    console.log(e);
  });
</script>

<!-- CORRECT -->
<script>
  document.querySelector('mds-pref-mode').addEventListener('mdsPrefChange', (e) => {
    console.log(e.detail.preference);
  });
</script>
```
