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

# mds-calendar

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

The `<mds-calendar>` web component is the date-selection surface of the Magma Design System: a localized month grid that lets users pick either a single day or a date range. It is the visual engine behind `mds-input-date` and `mds-input-date-range`.

#### Semantic Behavior

- **Range vs. single mode**: range selection is the default; set `singlePicker` to pick one day. In range mode the first click sets the start, the second sets the end, and a third click starts a new range from the clicked day; in single mode each click replaces the prior choice.
- **Active end**: a parent that lets the user choose which end to change, as [`mds-input-date-range`](../mds-input-date-range/AGENTS.md) does, names it in `activeEnd` (`start` or `end`): a click then changes that end only, also on a complete range, instead of starting a new one. With no start, a click picks the start whatever `activeEnd` says.
- **Never backwards**: a click never swaps the ends. A day before the start, clicked while the end is picked, becomes the new start and the end is still to pick; a day after the end, clicked while the start is picked (`activeEnd="start"`), becomes the new start and the end is emptied. A `startDate` / `endDate` pair given backwards, in the markup or from code, is put in order (with a console warning); a parent that sets the two props one after the other is read once both have arrived, so a start moved past the old end is not taken for a range given backwards.
- **Hover preview**: While a range waits for its end, the day under the pointer is previewed: the band from the start to that day when a click there would end the range, that day alone when it would become a new start. The preview is dropped with the click that changes the range.
- **Marks**: a chosen day, either end of a range or the day of a single picker, is a full dot, the start and the end alike, and the days between them a band; the day under the pointer, not chosen yet, is a ring on a paler band.
- **Min/max bounds**: `min` and `max` mark out-of-range day cells as disabled, blocking their selection.
- **Multi-view navigation**: The header toggles between the day grid, a month picker, and a year picker; the year view pages in decades while the calendar view pages month by month. The two arrows are icon-only buttons named in the page language (the `lang` of `<html>`): previous / next month on the day grid, previous / next years in the year view; the month picker has nothing to page through, so there they are disabled. The header is a navigation landmark named after the month and year it shows, so two calendars side by side are two distinct landmarks.
- **Localization**: Weekday names, month names, and cell titles are formatted in the page language (the `lang` attribute of `<html>`, `en` when absent).
- **Emitted events**: `mdsCalendarChange` fires on every pick with `{ startDate, endDate? }`: in range mode the first click emits `{ startDate }` alone, the second the full range; `mdsCalendarPreselect` fires only with a completed range, to let preselection shortcuts re-evaluate their state.
- **Preselection slot**: A `preselection` named slot hosts quick-pick shortcuts. The area appears while the slot holds an element, one added after load included; `hidePreselection` collapses it. The `date-preselection--has-preselection` class earlier versions required is no longer needed (it still shows the area).

#### Properties & Visual Configurations

Dates are exchanged as ISO 8601 strings (`YYYY-MM-DD`). `startDate` and `endDate` seed the selection (a click updates the internal selection and emits `mdsCalendarChange`, it does not rewrite the attributes); on load, a valid `startDate` also determines which month is shown first.

- **`singlePicker`** is the mode switch: omit it for two-ended range selection, set it for single-day pickers. When set, any `endDate` is ignored and cleared with a warning.
- **`activeEnd`** names the end the next click picks, for a parent that shows the user which one it is; leave it unset on a calendar standing alone.
- **`hidePreviousButton`** / **`hideNextButton`** remove one of the header navigation buttons, typically on calendars paired side by side; **`disableMonthYearSelection`** keeps the header on the day grid; **`hideToday`** removes the highlight on today's date.
- Every boolean prop defaults to `false`: the feature is on until the bare attribute turns it off.
- **`min`** / **`max`** define the selectable window; days outside it render disabled rather than being hidden.

This component does not use the shared `variant` / `tone` ladders on its host - those are defined in [`agents/variants.md`](../../../../agents/variants.md) and are applied internally to the navigation buttons it renders.

## 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/ui-calendar--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 |
| --- | --- | --- | --- | --- |
| `activeEnd` | `active-end` | `"end" \| "start" \| undefined` | - | Specifies the end of the range the next click picks, `start` or `end`, for a parent that lets the user choose it, as `mds-input-date-range` does from its fields and from the header of its panel. A click never puts the range backwards: a day after the end, picked as the start, becomes the new start and empties the end; a day before the start, picked as the end, becomes the new start and leaves the end to pick. With no start, a click picks the start. Left unset, the calendar picks the start, then the end, and a click on a complete range starts a new one. |
| `disableMonthYearSelection` | `disable-month-year-selection` | `boolean` | `false` | Disables switching to month or year selection views from the calendar header. |
| `endDate` | `end-date` | `null \| string` | `null` | Specifies the end date of the selection |
| `hideNextButton` | `hide-next-button` | `boolean` | `false` | If set, the component hides the next navigation button in the calendar header. |
| `hidePreselection` | `hide-preselection` | `boolean` | `false` | If set, the component hides the preselection area above the calendar view even when the `preselection` slot has content. |
| `hidePreviousButton` | `hide-previous-button` | `boolean` | `false` | If set, the component hides the previous navigation button in the calendar header. |
| `hideToday` | `hide-today` | `boolean` | `false` | Hides the highlight on today's date in the calendar view. |
| `hoverDate` | `hover-date` | `null \| string` | `null` | Specifies the date used to preview the range selection across multiple visible calendars. |
| `max` | `max` | `null \| string` | `null` | Specifies the minimum date of the selection |
| `min` | `min` | `null \| string` | `null` | Specifies the minimum date of the selection |
| `singlePicker` | `single-picker` | `boolean` | `false` | If set, the component selects a single date instead of a date range (start and end date). |
| `startDate` | `start-date` | `null \| string` | `null` | Specifies the start date of the selection |
| `viewDate` | `view-date` | `null \| string` | `null` | Specifies the date used to determine the visible month without changing the selection. |

## Events

| Event | Detail | Description |
| --- | --- | --- |
| `mdsCalendarChange` | `{ startDate: string; endDate?: string \| undefined; }` | Emitted when the selected date or date range changes. |
| `mdsCalendarHover` | `{ hoverDate: string \| null; }` | Emitted when the user hovers over a day, used to preview a range selection. |
| `mdsCalendarNavigate` | `{ currentDate: string; delta: number; }` | Emitted when the user navigates to a different month or year. |
| `mdsCalendarPreselect` | `void` | Emitted when the calendar's preselection options need to be re-evaluated. |

## Methods

| Method | Signature | Description |
| --- | --- | --- |
| `updateCurrentDate` | `updateCurrentDate(date: string) => Promise<void>` | Sets the calendar's current date and re-renders the calendar accordingly. |

## Slots

| Slot | Description |
| --- | --- |
| `preselection` | Add `HTML elements` or `components` shown in the calendar preselection area. |

## CSS custom properties

| Property | Description |
| --- | --- |
| `--mds-calendar-background` | The background color of the calendar container. |
| `--mds-calendar-border-radius` | The border-radius of the calendar container. |
| `--mds-calendar-cell-other-month-visibility` | Controls visibility of days from other months (e.g. "visible", "hidden"). |
| `--mds-calendar-padding` | The internal padding of the calendar container. |

Only these are public. Its other 5 are internal: they may change in any release, do not set them.

## Dependencies

Uses: `mds-button`, `mds-calendar-cell`.
Used by: `mds-input-date`, `mds-input-date-range`.
