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

# mds-button-dropdown - mistakes

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

Common incorrect uses of `<mds-button-dropdown>`. 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 Put the Label in the Default Slot

The default slot feeds the `<mds-dropdown>` panel, not the button label. Text placed in the slot ends up as menu content, not as the button's visible text. Use the `label` prop.

```html
<!-- INCORRECT -->
<mds-button-dropdown variant="primary" tone="strong">
  Salva
</mds-button-dropdown>

<!-- CORRECT -->
<mds-button-dropdown label="Salva" variant="primary" tone="strong">
  <mds-button variant="dark" tone="text" label="Salva come bozza"></mds-button>
</mds-button-dropdown>
```

#### Do Not Slot Non-Button Content as Menu Items

The dropdown panel is designed for [`mds-button`](../mds-button/AGENTS.md) elements. Slotting raw `<button>`, `<a>`, or arbitrary HTML bypasses the Magma theming, focus styles and button API (`icon`, `await`, `disabled`) of the menu entries.

```html
<!-- INCORRECT -->
<mds-button-dropdown label="Esporta" variant="primary" tone="weak">
  <button onclick="exportPDF()">PDF</button>
  <a href="/export/csv">CSV</a>
</mds-button-dropdown>

<!-- CORRECT -->
<mds-button-dropdown label="Esporta" variant="primary" tone="weak">
  <mds-button variant="dark" tone="text" label="Esporta PDF" icon="mi/baseline/picture-as-pdf"></mds-button>
  <mds-button variant="dark" tone="text" label="Esporta CSV" icon="mi/baseline/table-chart"></mds-button>
</mds-button-dropdown>
```

#### Do Not Count on the Default `type` to Submit a Form

Unlike `<mds-button>`, the component defaults to `type="button"`: inside a form, the primary action submits nothing until you set `type="submit"`.

```html
<!-- INCORRECT: the primary action does not submit -->
<form action="/mail" method="post">
  <mds-button-dropdown name="action" value="send" label="Invia">
    <mds-button name="action" value="draft" variant="dark" tone="text" label="Salva come bozza"></mds-button>
  </mds-button-dropdown>
</form>

<!-- CORRECT -->
<form action="/mail" method="post">
  <mds-button-dropdown type="submit" name="action" value="send" label="Invia">
    <mds-button name="action" value="draft" variant="dark" tone="text" label="Salva come bozza"></mds-button>
  </mds-button-dropdown>
</form>
```

#### Do Not Submit the Form from a `click` Listener

A `click` listener on the component also runs for the menu items, whose clicks bubble to it: picking a menu item that submits ("Salva come bozza") submits the form twice, once with its `name` / `value` and once without, and the receiver cannot tell which action was chosen. Use `type="submit"` with `name` / `value`.

```html
<!-- INCORRECT -->
<mds-button-dropdown id="send" label="Invia"></mds-button-dropdown>
<script>
  document.getElementById('send').addEventListener('click', () => form.requestSubmit());
</script>

<!-- CORRECT -->
<mds-button-dropdown type="submit" name="action" value="send" label="Invia"></mds-button-dropdown>
```

#### Do Not Listen to `click` for the Primary Action

A `click` on the component also comes from the menu items, whose clicks bubble to it: the primary action would run whenever the user picks an entry of the menu. Listen for `mdsButtonDropdownClick`, which only the primary action emits.

```js
// INCORRECT: also runs for "Salva come copia"
dropdown.addEventListener('click', () => save());

// CORRECT
dropdown.addEventListener('mdsButtonDropdownClick', () => save());
```

#### Do Not Leave a Menu Item That Must Not Submit on the Default `type`

The menu items are slotted `<mds-button>`, whose `type` defaults to `'submit'`: inside a form, an item that runs your own code (a preview, a copy) submits the form too. Give it `type="button"`.

```html
<!-- INCORRECT: "Anteprima" submits the form -->
<mds-button-dropdown type="submit" name="action" value="send" label="Invia">
  <mds-button variant="dark" tone="text" label="Anteprima"></mds-button>
</mds-button-dropdown>

<!-- CORRECT -->
<mds-button-dropdown type="submit" name="action" value="send" label="Invia">
  <mds-button type="button" variant="dark" tone="text" label="Anteprima"></mds-button>
</mds-button-dropdown>
```

#### Do Not Use Unsupported `tone` Values

`<mds-button-dropdown>` accepts `ToneMinimalVariantType`, which is `strong` and `weak` only. Passing `outline`, `text`, or `box` is not valid for this component: the value reaches the internal buttons unchecked, without the split-button styling that only `strong` and `weak` have.

```html
<!-- INCORRECT -->
<mds-button-dropdown label="Azione" variant="primary" tone="outline"></mds-button-dropdown>
<mds-button-dropdown label="Azione" variant="primary" tone="text"></mds-button-dropdown>

<!-- CORRECT -->
<mds-button-dropdown label="Azione" variant="primary" tone="strong">
  <mds-button variant="dark" tone="text" label="Opzione"></mds-button>
</mds-button-dropdown>
<mds-button-dropdown label="Azione" variant="primary" tone="weak">
  <mds-button variant="dark" tone="text" label="Opzione"></mds-button>
</mds-button-dropdown>
```

#### Do Not Try to Customize the Chevron Icon

The chevron trigger icon is internal and fixed. There is no prop to change it. Do not attempt to override it with CSS property hacks or shadow-DOM selectors.

```css
/* INCORRECT */
mds-button-dropdown .dropdown-action mds-icon {
  content: url('custom-arrow.svg');
}

/* CORRECT - style only through documented custom properties and the dropdown part */
mds-button-dropdown {
  --mds-button-dropdown-radius: var(--magma-radius-md);
}
mds-button-dropdown::part(dropdown) {
  box-shadow: var(--shadow-lg);
}
```

#### Do Not Name the Chevron with `aria-label` on the Host

The host has no role, so an `aria-label` on it names nothing, and it never reaches the chevron inside. The chevron is already named after `label` ("Altre azioni per Esporta"); give it a name of your own with `dropdown-label`.

```html
<!-- INCORRECT -->
<mds-button-dropdown label="Esporta" aria-label="Formati di esportazione">
  <mds-button variant="dark" tone="text" label="PDF"></mds-button>
</mds-button-dropdown>

<!-- CORRECT -->
<mds-button-dropdown label="Esporta" dropdown-label="Formati di esportazione">
  <mds-button variant="dark" tone="text" label="PDF"></mds-button>
</mds-button-dropdown>
```

#### Do Not Set Boolean Attributes to `"false"`

`await`, `disabled`, and `active` are boolean attributes and `mds-button-dropdown` is form-associated: as on a native control, any value turns them on, `"false"` included, so this markup renders a disabled button that is waiting. Remove the attribute to turn it off.

```html
<!-- INCORRECT -->
<mds-button-dropdown label="Invia" await="false" disabled="false" variant="primary"></mds-button-dropdown>

<!-- CORRECT -->
<mds-button-dropdown label="Invia" variant="primary" tone="strong">
  <mds-button variant="dark" tone="text" label="Invia come bozza"></mds-button>
</mds-button-dropdown>
```
