<!--
  GENERATED FILE - do not edit by hand.
  Source of truth: src/components/mds-input-range/ in the magma monorepo (usage/*.md and the
  component's JSDoc). Regenerated on every stencil build (scripts/component-docs.ts).
-->

# mds-input-range

> `@maggioli-design-system/magma` 2.15.0. Shadow DOM: style it only through the public CSS custom properties and the parts below.

The `<mds-input-range>` web component is the Magma Design System slider control for picking a numeric value from a continuous interval, or several values on one track. It wraps a native `<input type="range">` per thumb, adding a labelled header, a styled track with a live progress fill, form association, and value formatting.

#### Semantic Behavior

- **Form association**: Inside a `<form>` the selected number is reported under `name` with no extra wiring. A form reset brings back the value of load, thumb and progress included, or the middle of the range when the markup sets no `value`, like a native input.
- **Value clamping and snapping**: On input the value is clamped into `[min, max]` and snapped to the nearest `step` increment, so the committed `value` is always valid even when set programmatically out of range.
- **Decimal awareness**: The number of decimal places is derived from `step`, letting fractional steps snap correctly; as on a native input, a `step` that is not a positive number, from the start or set later, falls back to the default step, `1`.
- **Disabled state**: Blocks interaction and clears the reported form value while disabled; enabled again, the range reports its value again. A disabled `<fieldset>` around the component does the same, as it does a native input.
- **Emitted event**: `mdsInputRangeChange` carries the new numeric value whenever `value` actually changes.
- **Accessibility**: The control takes its accessible name from the slotted label text; with `formatValue` it also announces the formatted value (`aria-valuetext`). The ring of the focus goes round the thumb.
- **Default slot is the label**: The default slot holds the field's text label, rendered in the header alongside the formatted current value.
- **Tip over the thumb**: while the pointer is on the slider, while the thumb is dragged and while it has the focus of the keyboard, the thumb shows its value, formatted as in the header, in a tip over it; the header keeps the value, for when nothing moves, and a header hidden through its `header` part leaves the tip. The tip follows its thumb, its arrow on the thumb and its bubble inside the track at the ends; it lies on the line of the header, its value on the line of the header value, and covers whole the part of the header it meets. It is drawn only, since the thumb already announces its value.
- **Width**: The slider takes the width its container gives it, a narrow grid cell too: the track gets shorter and a label longer than the room left by the value ends in an ellipsis.

#### Several Values on One Track

An [`<mds-input-range-value>`](../mds-input-range-value/AGENTS.md) child per value turns the range into a slider with a thumb per value, as an `<option>` per choice turns a `<select>` into a list: a minimum and a maximum, or the stops of a scale.

- **From the first child on**: with one child or more, the values are the children's, one child included; `value` and `mdsInputRangeChange` are left out, and keep the one value of a range without children.
- **One native input per thumb**: each thumb is a native range input, all of them stacked on the track. The native input gives the slider role, the value, the name, the focus and the drag; a component of `role="slider"` elements would rewrite them, and leave the one value on another control.
- **Neighbours bound each other**: a thumb never passes the thumbs next to it, but can reach them. The arrows move the thumb with the focus by one `step`, Page Up and Page Down by a tenth of the range, Home and End take it to its neighbours (or to `min` and `max`): the component handles these keys itself, because a native input knows only `min` and `max`.
- **Order and limits of the markup**: the thumbs follow the values from the lowest, whatever the order of the children; each keeps the name of its own child. A value outside `min` and `max`, or off the step, is brought inside and onto the step, as a native input sanitizes it, and written back on its child; a child without a value starts in the middle.
- **Names**: the text of the range names the group of thumbs, the text of each child names its thumb, as in the multi-thumb slider of the WAI-ARIA APG. A child without text gets the label and the position of its thumb ("Prezzo, 1 di 2", in the language of the page).
- **Header**: the values in order, formatted as the one value: two are an interval joined by an en dash ("20 - 80" with a long dash), more a list joined by a middle dot.
- **Tip over each thumb**: each thumb has its own tip, with its own value. The one value shows its tip with the pointer anywhere on the track, its input taking the whole track; with two thumbs or more, the pointer finds a thumb only on the thumb, and its tip shows then.
- **Fill**: from the first thumb to the last.
- **Overlap**: a thumb is as wide as the track is tall, so two near values lie on each other: the thumb with the focus lies on top and the keys move it alone. Without the focus, a thumb held by its neighbours lies under them, so that the one on top can move.
- **Pointer**: a thumb drags itself; a press on the track moves the nearest thumb there.
- **Adding and removing**: adding a value is adding a child, removing one is removing it; the range watches its children, their values and their text.
- **Form**: an entry per value under `name`, in order, as a native `<select multiple>`; a form reset gives each child back the value it had when the range first read it.
- **Event**: `mdsInputRangeValuesChange` carries `{ values }`, in order, whenever the list changes: from a thumb, from code, as a child comes or goes, on a reset. The values of load are not a change.

#### Properties & Visual Configurations

- **`min` / `max` / `step`** define the permitted interval and granularity; `step` also controls how fractional values are snapped and how many decimals are preserved.
- **`value`** is the committed numeric selection of a range without `<mds-input-range-value>` children, kept clamped and snapped - set it programmatically to move the thumb. With children, each child holds the value of its thumb.
- **`formatValue`** is a function `(value: number) => string` for presentation only: use it to render the header value as currency, a percentage, or a unit-suffixed label without changing the underlying numeric `value`.

This component does not use the shared `variant` / `tone` ladders ([`agents/variants.md`](../../../../agents/variants.md)); it has no public CSS custom property: the thumb and the track follow the theme, and the `header` and `track` parts listed in [`AGENTS.md`](AGENTS.md) are its styling hooks.

## Read next

- [`examples.md`](examples.md) - correct usage, from the most common case
- [`mistakes.md`](mistakes.md) - the wrong forms, each with the right one
- [Storybook](https://magma-design-system.github.io/magma/storybook/?path=/docs/form-range--docs) - the live examples, in the published Storybook of `main`
- [`conventions.md`](../../../../agents/conventions.md), [`variants.md`](../../../../agents/variants.md), [`mistakes.md`](../../../../agents/mistakes.md) - the rules shared by every component

## Props

| Prop | Attribute | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `disabled` | `disabled` | `boolean \| undefined` | - | Sets if the component is disabled |
| `formatValue` | - | `((value: number) => string) \| undefined` | - | A function to custom how value is represented |
| `max` | `max` | `number` | `100` | The greatest value in the range of permitted values |
| `min` | `min` | `number` | `0` | The lowest value in the range of permitted values |
| `name` | `name` | `string \| undefined` | - | Is needed to reference the form data after the form is submitted |
| `step` | `step` | `number` | `1` | The step attribute is a number that specifies the granularity that the value must adhere to, or the special value any, which is described below. |
| `value` | `value` | `number` | - | The value attribute contains a number which contains a representation of the selected number. It holds the one value of a range without `mds-input-range-value` children: with children the values are theirs, and this one is left out |

## Events

| Event | Detail | Description |
| --- | --- | --- |
| `mdsInputRangeChange` | `number` | Emits when the input range is changed: the value of a range without `mds-input-range-value` children |
| `mdsInputRangeValuesChange` | `MdsInputRangeValuesEventDetail` | Emits when the values of a range with `mds-input-range-value` children change: from a thumb, from code, as a child comes or goes, or on a form reset. `values` holds them in order, from the lowest. The values of load are not a change |

## Slots

| Slot | Description |
| --- | --- |
| (default) | The label of the range, as text. Add an `mds-input-range-value` per value to hold several values, a thumb each, on one track |

## Parts

| Part | Description |
| --- | --- |
| `header` | The element containing the labels displayed over the input element |
| `track` | The element containing the track of the input range |

## CSS custom properties

None is public: its 9 custom properties are internal and may change in any release. Style it with its props, its parts and the semantic roles.

## Dependencies

Uses: `mds-text`.
