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

# mds-input-date-range-preselection - examples

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

Correct and idiomatic ways to use the `<mds-input-date-range-preselection>` component, ordered from most common to most specialized. The examples assume a working knowledge of the shared component rules in [`agents/conventions.md`](../../../../agents/conventions.md).

#### Basic Preset Range Shortcuts

Place one or more `<mds-input-date-range-preselection>` elements as direct children of [`<mds-input-date-range>`](../mds-input-date-range/AGENTS.md). Each element needs a `start` date (ISO format) and a human-readable label in its default slot. The component auto-assigns itself to the parent's `calendar-preselection` slot.

```html
<mds-input-date-range name="periodo">
  <mds-input-date slot="start"></mds-input-date>
  <mds-input-date slot="end"></mds-input-date>
  <mds-input-date-range-preselection start="2025-06-01" end="2025-06-30">
    Questo mese
  </mds-input-date-range-preselection>
  <mds-input-date-range-preselection start="2025-05-01" end="2025-05-31">
    Mese scorso
  </mds-input-date-range-preselection>
  <mds-input-date-range-preselection start="2025-01-01" end="2025-12-31">
    Anno corrente
  </mds-input-date-range-preselection>
</mds-input-date-range>
```

#### Single-Day Shortcut (omit `end`)

Omit the `end` attribute to create a single-day preselection. The parent matches it as active whenever its current range is a single day equal to `start`.

```html
<mds-input-date-range name="data-singola">
  <mds-input-date slot="start"></mds-input-date>
  <mds-input-date slot="end"></mds-input-date>
  <mds-input-date-range-preselection start="2025-06-05">
    Oggi
  </mds-input-date-range-preselection>
</mds-input-date-range>
```

#### Multiple Preset Windows Together

Group semantically related shortcuts - short-term, medium-term, and long-term - so users can jump to the most common reporting windows without picking the dates on the calendar (the presets sit in the calendar dropdown, next to the calendar). Only one item carries `selected` at a time; the parent manages it automatically.

```html
<mds-input-date-range name="finestra-report">
  <mds-input-date slot="start"></mds-input-date>
  <mds-input-date slot="end"></mds-input-date>
  <mds-input-date-range-preselection start="2025-05-29" end="2025-06-04">
    Ultima settimana
  </mds-input-date-range-preselection>
  <mds-input-date-range-preselection start="2025-05-01" end="2025-05-31">
    Ultimo mese
  </mds-input-date-range-preselection>
  <mds-input-date-range-preselection start="2025-01-01" end="2025-06-30">
    Ultimo semestre
  </mds-input-date-range-preselection>
  <mds-input-date-range-preselection start="2024-01-01" end="2024-12-31">
    Anno precedente
  </mds-input-date-range-preselection>
</mds-input-date-range>
```

#### Reading the Selected Value via Parent Events

Listen to the parent's `mdsInputDateRangeValueChange` event to read the chosen range. The preselection component itself fires no event - the parent owns the value contract.

```html
<mds-input-date-range id="date-range" name="periodo">
  <mds-input-date slot="start"></mds-input-date>
  <mds-input-date slot="end"></mds-input-date>
  <mds-input-date-range-preselection start="2025-06-01" end="2025-06-30">
    Questo mese
  </mds-input-date-range-preselection>
</mds-input-date-range>

<script>
  document.getElementById('date-range').addEventListener('mdsInputDateRangeValueChange', (e) => {
    console.log(e.detail.startDate, e.detail.endDate);
  });
</script>
```

#### Styling Customization

`<mds-input-date-range-preselection>` has no public CSS custom property and no shadow part: it paints its three visual states - default, hover, and selected - from the semantic color roles ([`agents/color.md`](../../../../agents/color.md)), so dark mode and themes keep working without overrides. The parent marks the active shortcut with `selected`; do not restyle the states by hand.
