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

# mds-pref-mode - mistakes

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

Common incorrect uses of `<mds-pref-mode>`. 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 `<mds-pref-mode>` Outside `<mds-pref>`

`<mds-pref-mode>` is a compound child: `<mds-pref>` forwards `size` changes to it. As a standalone widget it still applies and persists the mode, and it still follows a theme of one mode, which it reads from `<html>`; only the forwarding of `size` is lost.

```html
<!-- INCORRECT -->
<mds-pref-mode></mds-pref-mode>

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

#### Do Not Set `transition="false"` to Disable the Overlay

`transition` is a string enum, not a boolean. `"false"` is not a valid value: it only happens to fall through to the no-overlay branch, with no guarantee across releases. Use `transition="none"` to opt out of the overlay animation.

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

<!-- CORRECT -->
<mds-pref-mode transition="none"></mds-pref-mode>
```

#### Do Not Listen for Native `change` Events Instead of `mdsPrefChange`

The component does not emit or bubble native `change` events out of the shadow DOM. Always listen for the documented `mdsPrefChange` custom event.

```html
<!-- INCORRECT -->
<script>
  document.querySelector('mds-pref-mode').addEventListener('change', handler);
</script>

<!-- CORRECT -->
<script>
  document.querySelector('mds-pref-mode').addEventListener('mdsPrefChange', handler);
</script>
```

#### Do Not Override Mode Classes on `<html>` Directly

The component manages `pref-mode-light`, `pref-mode-dark`, and `pref-mode-system` classes on `<html>` itself. Adding or removing these by hand races with the component and will be overwritten on the next mode change. Drive the mode exclusively through the `mode` prop.

```html
<!-- INCORRECT -->
<script>
  document.documentElement.classList.add('pref-mode-dark');
</script>

<!-- CORRECT -->
<mds-pref>
  <mds-pref-mode mode="dark"></mds-pref-mode>
</mds-pref>
```

#### Do Not Size Only One Child of the Panel

Setting `size` on `<mds-pref-mode>` alone when siblings exist produces inconsistent tab sizes across the panel. Set it on `<mds-pref>`, which forwards it to every preference child, on load and when it changes.

```html
<!-- INCORRECT -->
<mds-pref>
  <mds-pref-mode size="sm"></mds-pref-mode>
  <mds-pref-contrast></mds-pref-contrast>
</mds-pref>

<!-- CORRECT -->
<mds-pref size="sm">
  <mds-pref-mode></mds-pref-mode>
  <mds-pref-contrast></mds-pref-contrast>
</mds-pref>
```

#### Do Not Target the Injected Overlay to Customize It

The overlay element is injected into `document.body` at runtime with inline styles, which win over a class selector anyway. Do not target it by class name or adjust its properties through JavaScript. Use the public `--mds-pref-mode-overlay-z-index` CSS custom property instead.

```css
/* INCORRECT */
.mds-pref-mode-overlay {
  background-color: black;
  z-index: 99999;
}

/* CORRECT */
mds-pref-mode {
  --mds-pref-mode-overlay-z-index: 9000;
}
```
