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

# mds-input - mistakes

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

Common incorrect uses of `<mds-input>`. 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 a Raw `<input>` When `<mds-input>` Exists

Reaching for a plain `<input>` bypasses theming, validation, tips, accessible state announcements, and form-reset behavior provided by the component.

```html
<!-- INCORRECT -->
<input type="text" name="nome" placeholder="Nome" class="my-input">

<!-- CORRECT -->
<mds-input name="nome" type="text" placeholder="Nome"></mds-input>
```

#### Do Not Use a Native `<input type="color">` in a Form of Magma

The native colour input looks like no other field of the form, has no text to type or paste a code into, no message, no variant and no label of `mds-input-field`, and always holds a colour (`#000000`), so it cannot be left empty. `type="color"` gives the field of Magma with the picker of the platform on the button at its end.

```html
<!-- INCORRECT -->
<label>Colore di base <input type="color" name="base" value="#2f6fd0"></label>

<!-- CORRECT -->
<mds-input-field label="Colore di base">
  <mds-input type="color" name="base" value="#2f6fd0"></mds-input>
</mds-input-field>
```

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

`disabled`, `required`, `readonly`, `mic` and `await` are boolean attributes: remove the attribute entirely to turn it off. `mds-input` is form-associated, so as on a native control any value turns them on, `"false"` included: this markup renders a disabled, required field.

```html
<!-- INCORRECT -->
<mds-input name="note" disabled="false" required="false"></mds-input>

<!-- CORRECT -->
<mds-input name="note"></mds-input>
```

#### Do Not Force `variant` for Validation Feedback

The component drives `variant` to `'success'` or `'error'` automatically on blur when validators are active. Setting `variant` manually overrides the feedback and breaks the visual contract.

```html
<!-- INCORRECT -->
<mds-input name="codice" variant="error" tip="Valore non valido"></mds-input>

<!-- CORRECT -->
<mds-input name="codice" required tip="Inserisci un valore valido"></mds-input>
```

#### Do Not Listen to Native `input` or `change` Events

The native `change` event does not cross the shadow boundary, and `input` reports only typing, not the values set by the steppers, the dictation or a script. Use the documented `mdsInputChange` event instead, which fires for every value change.

```javascript
// INCORRECT
document.querySelector('mds-input').addEventListener('input', (e) => {
  console.log(e.target.value);
});

// CORRECT
document.querySelector('mds-input').addEventListener('mdsInputChange', (e) => {
  console.log(e.detail.value);
});
```

#### Do Not Use `type="number"` Native Browser Spinners and Then Override the Input

The component renders its own increment/decrement buttons and hides the native browser spinners. Do not try to re-enable them via CSS, and do not add inline JS `stepUp`/`stepDown` calls - use the `controlsLayout` and `controlsIcon` props to configure the built-in controls.

```html
<!-- INCORRECT -->
<mds-input type="number" style="-moz-appearance: auto;"></mds-input>

<!-- CORRECT -->
<mds-input
  type="number"
  controls-layout="horizontal"
  controls-icon="arithmetic"
  min="0"
  max="100"
></mds-input>
```

#### Do Not Use a Legacy or Invalid `type` Value

`<mds-input>` accepts a specific set of `type` values: `text`, `email`, `number`, `password`, `search`, `tel`, `url`, `date`, `time`, `textarea`, `cf`, `piva`, `cc`, `isbn`. Supplying anything else (e.g. `"checkbox"`, `"radio"`, `"file"`) is passed straight to the inner native `<input>`, which renders a bare native control that the component neither styles nor reports correctly to the form. Use the dedicated Magma component for those controls.

```html
<!-- INCORRECT -->
<mds-input type="checkbox" name="accetto"></mds-input>
<mds-input type="file"     name="allegato"></mds-input>

<!-- CORRECT -->
<mds-input-switch name="accetto"></mds-input-switch>
<mds-input-upload name="allegato"></mds-input-upload>
```

#### Do Not Use `placeholder` as the Accessible Label

`placeholder` disappears on input and is never read as a label by assistive tech. Always pair `<mds-input>` with [`mds-input-field`](../mds-input-field/AGENTS.md) (which shows a visible label and passes it down as the accessible name) or supply `aria-label` directly on the host.

```html
<!-- INCORRECT -->
<mds-input name="ricerca" placeholder="Cerca per nome"></mds-input>

<!-- CORRECT -->
<mds-input-field label="Cerca per nome">
  <mds-input name="ricerca" placeholder="Cerca per nome"></mds-input>
</mds-input-field>
```

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

The supported customization surface is the public `--mds-input-*` CSS custom properties plus the documented shadow parts (`field`, `tip-top`, `tip-bottom`, `tip-count`, `password-toggle-button`, `counter-button-increase`, `counter-button-decrease`, `mic-toggle-button`, `color-picker-button`). Targeting undocumented internals via `>>>` or arbitrary class names couples your code to the Shadow DOM implementation.

```css
/* INCORRECT */
mds-input >>> .input {
  border: 2px solid red;
}

/* CORRECT */
mds-input {
  --mds-input-ring: 0 0 0 2px rgb(var(--magma-danger-border));
  --mds-input-background: rgb(var(--magma-danger-wash-base));
}
mds-input::part(field) {
  font-style: italic;
}
```
