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

# mds-input-range - mistakes

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

Common incorrect uses of `<mds-input-range>`. 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 type="range">` Instead of the Component

Reaching for the native element bypasses the Magma-styled track, the progress fill, the labelled header, form association wiring, and the snapping logic.

```html
<!-- INCORRECT -->
<label for="v">Volume</label>
<input type="range" id="v" name="volume" min="0" max="100">

<!-- CORRECT -->
<mds-input-range name="volume" min="0" max="100">Volume</mds-input-range>
```

#### Do Not Omit the Label Slot

Without slotted text the slider has no accessible name - screen readers cannot announce the control's purpose. Always put a meaningful text label in the default slot.

```html
<!-- INCORRECT -->
<mds-input-range name="luminosita" min="0" max="100"></mds-input-range>

<!-- CORRECT -->
<mds-input-range name="luminosita" min="0" max="100">Luminosita</mds-input-range>
```

#### Do Not Use `disabled="false"` to Enable the Slider

`disabled` is a boolean attribute and `mds-input-range` is form-associated: as on a native control, any value turns it on, `"false"` included, so this markup disables the slider. Remove the attribute entirely to enable it.

```html
<!-- INCORRECT -->
<mds-input-range name="soglia" disabled="false">Soglia</mds-input-range>

<!-- CORRECT -->
<mds-input-range name="soglia">Soglia</mds-input-range>
```

#### Do Not Listen to Raw `input` / `change` Events

Native events may not bubble out of shadow DOM the way you expect. Listen to `mdsInputRangeChange`, which the component emits on every committed value change.

```html
<!-- INCORRECT -->
<mds-input-range id="r" name="valore">Valore</mds-input-range>
<script>
  document.querySelector('#r').addEventListener('change', (e) => {
    console.log(e.target.value); // unreliable across shadow DOM
  });
</script>

<!-- CORRECT -->
<mds-input-range id="r" name="valore">Valore</mds-input-range>
<script>
  document.querySelector('#r').addEventListener('mdsInputRangeChange', (e) => {
    console.log(e.detail); // numeric value, always reliable
  });
</script>
```

#### Do Not Set `step` to Zero or a Negative Number

A `step` of zero or negative is invalid: as on a native input it is ignored and the default step, `1`, applies instead, which is rarely the granularity you meant. Use a positive integer or decimal.

```html
<!-- INCORRECT -->
<mds-input-range name="q" step="0">Quantita</mds-input-range>
<mds-input-range name="q" step="-1">Quantita</mds-input-range>

<!-- CORRECT -->
<mds-input-range name="q" step="1">Quantita</mds-input-range>
```

#### Do Not Put Several Ranges Side by Side for One Interval

Two ranges for a minimum and a maximum let the minimum pass the maximum, and give the form two names. Put both values on one range.

```html
<!-- INCORRECT -->
<mds-input-range name="prezzo-min" value="100">Prezzo minimo</mds-input-range>
<mds-input-range name="prezzo-max" value="400">Prezzo massimo</mds-input-range>

<!-- CORRECT -->
<mds-input-range name="prezzo">
  Prezzo
  <mds-input-range-value value="100">Minimo</mds-input-range-value>
  <mds-input-range-value value="400">Massimo</mds-input-range-value>
</mds-input-range>
```

#### Do Not Set `value` on a Range with Values

With `<mds-input-range-value>` children, the values are theirs: `value` of the range and `mdsInputRangeChange` are left out. Set and read the values on the children, or listen to `mdsInputRangeValuesChange`.

```html
<!-- INCORRECT -->
<mds-input-range value="20">
  Prezzo
  <mds-input-range-value>Minimo</mds-input-range-value>
  <mds-input-range-value>Massimo</mds-input-range-value>
</mds-input-range>

<!-- CORRECT -->
<mds-input-range>
  Prezzo
  <mds-input-range-value value="20">Minimo</mds-input-range-value>
  <mds-input-range-value value="80">Massimo</mds-input-range-value>
</mds-input-range>
```

#### Do Not Pierce the Shadow DOM to Style the Track or Thumb

The component exposes `::part(header)` and `::part(track)` for all supported customization; it has no public CSS custom property, and the thumb and the track take their colours from the theme. Targeting internal class names via `>>>` or undocumented `::part()` names couples your code to the implementation and will break on minor releases.

```css
/* INCORRECT */
mds-input-range >>> .track-progress {
  background-color: hotpink;
}
mds-input-range::part(thumb) { /* "thumb" is not a documented part */
  border-radius: 0;
}

/* CORRECT */
mds-input-range::part(track) { /* "track" is a documented part */
  opacity: 0.8;
}
```

#### Do Not Use `formatValue` to Change the Submitted Form Value

`formatValue` is purely presentational - it only changes the header display string. The submitted form value is always the raw number. Do not rely on it for data transformation.

```html
<!-- INCORRECT: expecting the form to submit the formatted string -->
<mds-input-range id="p" name="prezzo">Prezzo</mds-input-range>
<script>
  // This changes what is shown but NOT what is submitted
  document.querySelector('#p').formatValue = (v) => v + ' EUR';
  // form.submit() still sends a plain number for "prezzo"
</script>

<!-- CORRECT: format on the server or in a submit handler using event.detail -->
<mds-input-range id="p" name="prezzo">Prezzo</mds-input-range>
<script>
  document.querySelector('#p').formatValue = (v) =>
    v.toLocaleString('it-IT', { style: 'currency', currency: 'EUR' });
  // The display is formatted; handle raw numeric value on submit separately
</script>
```
