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

# mds-header - mistakes

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

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

`<mds-header-bar>` is a compound child; it must be a direct slot child of `<mds-header>`, which relays breakpoint and appearance state down to it. Using the bar standalone breaks that communication: its hamburger has no menu to open, and appearance and auto-hide do not apply.

```html
<!-- INCORRECT -->
<mds-header-bar>
  <mds-img src="/logo.svg" alt="Logo"></mds-img>
</mds-header-bar>

<!-- CORRECT -->
<mds-header>
  <mds-header-bar>
    <mds-img src="/logo.svg" alt="Logo"></mds-img>
  </mds-header-bar>
</mds-header>
```

#### Do Not Reserve the Room of the Bar by Hand

The header stands in the flow at the top of the page and stays put as it scrolls: the page already starts under its bar. A `padding-top` or a margin that made room for a fixed bar doubles it.

```html
<!-- INCORRECT -->
<body class="pt-1700">
  <mds-header>
    <mds-header-bar>...</mds-header-bar>
  </mds-header>
  <main class="page-frame">...</main>
</body>

<!-- CORRECT -->
<body>
  <mds-header>
    <mds-header-bar>...</mds-header-bar>
  </mds-header>
  <main class="page-frame">...</main>
</body>
```

#### Do Not Wrap the Header Alone or Place It After the Content

Sticky holds inside the box of the parent: a header alone in a wrapper scrolls away with it, and a header placed after the content stands at the end of the page. Make it the first child of the element that holds the whole page.

```html
<!-- INCORRECT -->
<div class="top">
  <mds-header>
    <mds-header-bar>...</mds-header-bar>
  </mds-header>
</div>
<main class="page-frame">...</main>

<!-- CORRECT -->
<mds-header>
  <mds-header-bar>...</mds-header-bar>
</mds-header>
<main class="page-frame">...</main>
```

#### Do Not Drive Scroll Appearance with JavaScript When `appearance-set` Is Available

Manually toggling `appearance` on a scroll listener duplicates what `appearance-set` already handles declaratively, and once `appearance-set` is also set the component's own scroll handler rewrites `appearance` on every scroll.

```html
<!-- INCORRECT -->
<mds-header id="hdr" appearance="inline">
  <mds-header-bar>...</mds-header-bar>
</mds-header>
<script>
  window.addEventListener('scroll', () => {
    document.getElementById('hdr').appearance = window.scrollY > 300 ? 'stripe' : 'inline';
  });
</script>

<!-- CORRECT -->
<mds-header appearance-set="inline, stripe 300" appearance="inline">
  <mds-header-bar>...</mds-header-bar>
</mds-header>
```

#### Do Not Omit the `menu` Slot When Providing a Hamburger-Only Nav

If no `[slot="menu"]` child is present there is no modal to open, so the bar shows no hamburger icon whatever `menu` says: on the viewports where `nav` hides the navigation, nothing is left to navigate with. Always provide menu content when you want the mobile toggle to be visible.

```html
<!-- INCORRECT: no hamburger and, on mobile, no navigation -->
<mds-header menu="mobile">
  <mds-header-bar>
    <mds-img src="/logo.svg" alt="Logo"></mds-img>
    <mds-button slot="nav" label="Accedi" variant="dark" tone="outline"></mds-button>
  </mds-header-bar>
</mds-header>

<!-- CORRECT -->
<mds-header menu="mobile">
  <mds-header-bar>
    <mds-img src="/logo.svg" alt="Logo"></mds-img>
    <mds-button slot="nav" label="Accedi" variant="dark" tone="outline"></mds-button>
  </mds-header-bar>
  <div slot="menu">
    <mds-button label="Accedi" variant="dark" tone="outline"></mds-button>
  </div>
</mds-header>
```

#### Do Not Listen to Native `scroll` Events to Detect Auto-Hide State

The component already emits `mdsHeaderVisibilityChange` when the bar flips between hidden and visible. Attaching a second `scroll` listener couples your code to the same threshold logic and risks running out of sync.

```html
<!-- INCORRECT -->
<mds-header auto-hide="300" id="hdr">
  <mds-header-bar>...</mds-header-bar>
</mds-header>
<script>
  window.addEventListener('scroll', () => {
    const hidden = window.scrollY > 300;
    document.body.classList.toggle('header-hidden', hidden);
  });
</script>

<!-- CORRECT -->
<mds-header auto-hide="300" id="hdr">
  <mds-header-bar>...</mds-header-bar>
</mds-header>
<script>
  document.getElementById('hdr').addEventListener('mdsHeaderVisibilityChange', (e) => {
    document.body.classList.toggle('header-hidden', e.detail.visibility === 'hidden');
  });
</script>
```

#### Do Not Pierce Shadow DOM to Style the Internal Modal

The side-modal container is exposed as `::part(menu)` and its stacking is controllable via `--mds-header-z-index`. Do not use `>>>`, `/deep/`, or undocumented internal selectors.

```css
/* INCORRECT */
mds-header >>> .menu mds-modal {
  background: red;
}

/* CORRECT */
mds-header {
  --mds-header-z-index: 500;
}
mds-header::part(menu) {
  /* documented part - safe to target */
}
```
