# Calendar (`<z-calendar>`)

> Accessible date grid with keyboard navigation, a month/year jumper, marked and disabled dates, and i18n/icon overrides.

- **Kind:** hwc
- **Category:** inputs
- **Inherits:** `BaseCalendarMixin`, `InputMixin`, `Hwc`, `Base`

## Attributes

### Inherited from `BaseCalendarMixin`

| Attribute | Type | Default | From | Description |
| --- | --- | --- | --- | --- |
| `today` | `boolean` | `false` | `BaseCalendarMixin` | Selects today's date on initialization when no `value` is given. |
| `jumpable` | `boolean` | `false` | `BaseCalendarMixin` | Replaces the prev/next month buttons with a month select and a four-digit year input, each with its own stepper buttons. |
| `starts-with` | `number` | `0` | `BaseCalendarMixin` | First day of the week, from 0 (Sunday) to 6 (Saturday). |
| `disabled-dates` | `string` | `''` | `BaseCalendarMixin` | Comma-separated ISO dates (YYYY-MM-DD) that cannot be selected. |
| `marked-dates` | `string` | `''` | `BaseCalendarMixin` | Comma-separated ISO dates (YYYY-MM-DD) rendered with an indicator dot. |
| `view-date` | `string` | `new Date().toISOString().split('T')[0]` | `BaseCalendarMixin` | ISO date (YYYY-MM-DD) whose month is displayed; defaults to today in UTC. |
| `min` | `string` | `''` | `BaseCalendarMixin` | Earliest selectable date (ISO, inclusive). |
| `max` | `string` | `''` | `BaseCalendarMixin` | Latest selectable date (ISO, inclusive). |
| `weekday-format` | `'long' \| 'short' \| 'narrow'` | `'short'` | `BaseCalendarMixin` | Length of the weekday names in the header: `long`, `short`, or `narrow`. |
| `lang` | `string` | `'en-us'` | `BaseCalendarMixin` | BCP-47 locale for month names, weekday names, and day labels. |

### Inherited from `InputMixin`

| Attribute | Type | Default | From | Description |
| --- | --- | --- | --- | --- |
| `disabled` | `boolean` | `false` | `InputMixin` | Disables the control so it cannot be interacted with. |
| `form` | `string` | `''` | `InputMixin` | Associates the hidden form input with a form by id, even when the component sits outside that form. |
| `name` | `string` | `''` | `InputMixin` | Field name for the hidden form input; array values submit as `name[]`. |
| `placeholder` | `string` | `''` | `InputMixin` | Placeholder text for the control's empty state. |
| `required` | `boolean` | `false` | `InputMixin` | Marks the control as required. |
| `value` | `string` | `''` | `InputMixin` | Initially selected date (YYYY-MM-DD); also sets the month shown on initialization. |

### Inherited from `Hwc`

| Attribute | Type | Default | From | Description |
| --- | --- | --- | --- | --- |
| `i18n` | `string` | `''` | `Hwc` | Per-instance text overrides as `key: text` pairs, merged over the global `z-i18n` script and the built-in defaults. |
| `floating` | `string` | `''` | `Hwc` | Floating UI placement options (for example `offset` and `shiftPadding`) parsed as `key: value` pairs. |
| `force-prevent-rerender` | `boolean` | `false` | `Hwc` | Skips re-rendering after the first render; an existing `data-host-inner` child is adopted as the rendered DOM. |
| `template` | `string` | `''` | `Hwc` | Selector or id of an external element or `<template>` whose inner content is cloned in place of an inline `template[data-fn="template"]` child. |

### Inherited from `Base`

| Attribute | Type | Default | From | Description |
| --- | --- | --- | --- | --- |
| `cls` | `string` | `''` | `Base` | Adds classes to named parts as `key: classes` pairs; a plain string targets the default part. |
| `stl` | `string` | `''` | `Base` | Adds inline styles to named parts as `key: styles` pairs; a plain string targets the default part. |

## Styling Parts (`cls` / `stl`)

Default `cls` target: `host-inner`. Default `stl` target: `host-inner`.

| Key | Default class | cls | stl | Description |
| --- | --- | --- | --- | --- |
| `button-marked` | `z-nothing` | ✓ | — | Class on the buttons of marked dates. |
| `button-outside-month` | `z-nothing` | ✓ | — | Class on the buttons of outside-month days. |
| `button-selected` | `z-nothing` | ✓ | — | Class on the selected day's button. |
| `button-today` | `z-nothing` | ✓ | — | Class on today's button. |
| `day` | — | ✓ | ✓ | Day cell wrapper; carries selected, today, marked, and outside-month state classes. |
| `day-button` | — | ✓ | ✓ | Focusable button inside each day cell. |
| `day-marked` | `z-cal-marked` | ✓ | — | Class on cells whose date is listed in `marked-dates`. |
| `day-outside-month` | `z-cal-oom` | ✓ | — | Class on cells belonging to the previous or next month. |
| `day-selected` | `z-active` | ✓ | — | Class on the selected day cell. |
| `day-today` | `z-nothing` | ✓ | — | Class on today's day cell. |
| `grid` | — | ✓ | ✓ | Table laying out the weekday header and week rows. |
| `header` | `z-cal-header` | ✓ | ✓ | Month navigation bar above the grid. |
| `host-inner` | `z-cal` | ✓ | ✓ | Outer calendar wrapper; the default `cls` and `stl` target. |
| `jumper` | `z-cal-jumper` | ✓ | ✓ | Month and year stepper container shown when `jumpable` is set. |
| `jumper-button` | `z-button z-button-secondary z-button-icon z-button-small` | ✓ | ✓ | Stepper button shared by the month and year groups. |
| `jumper-month` | `z-cal-jumper-month` | ✓ | ✓ | Month group: stepper buttons around the month select. |
| `jumper-year` | `z-cal-jumper-year` | ✓ | ✓ | Year group: stepper buttons around the year input. |
| `month-select` | `z-select z-form-small` | ✓ | ✓ | Dropdown of month names. |
| `next-button` | `z-button z-button-secondary z-button-icon z-button-small` | ✓ | ✓ | Button that steps to the next month. |
| `previous-button` | `z-button z-button-secondary z-button-icon z-button-small` | ✓ | ✓ | Button that steps to the previous month. |
| `title` | `z-cal-title` | ✓ | ✓ | Month and year label, or the jumper when `jumpable` is set. |
| `week` | — | ✓ | ✓ | Row of seven day cells. |
| `weekday` | — | ✓ | ✓ | Single weekday header cell. |
| `weekdays` | — | ✓ | ✓ | Header row of weekday names. |
| `year-input` | `z-input z-form-small` | ✓ | ✓ | Four-digit year input. |

## CSS Variables

| Variable | Default | Scope | Affects | Description |
| --- | --- | --- | --- | --- |
| `--z-cal-cell-active-bg` | `var(--z-primary)` | `.z-cal table tbody tr td.z-active button` | `background-color` | Background color of the selected day button. |
| `--z-cal-cell-active-bg-o` | `100%` | `.z-cal table tbody tr td.z-active button` | `background-color` | Opacity applied to the selected day background. |
| `--z-cal-cell-active-color` | `var(--z-primary-f)` | `.z-cal table tbody tr td.z-active button` | `color` | Text color of the selected day. |
| `--z-cal-cell-active-color-o` | `100%` | `.z-cal table tbody tr td.z-active button` | `color` | Opacity applied to the selected day text color. |
| `--z-cal-cell-body-font-size` | `1rem` | `.z-cal table tbody tr td` | `font-size` | Font size of the day numbers. |
| `--z-cal-cell-header-color` | `var(--z-muted-f)` | `.z-cal table thead th` | `color` | Text color of the weekday headers. |
| `--z-cal-cell-header-color-o` | `100%` | `.z-cal table thead th` | `color` | Opacity applied to the weekday header text color. |
| `--z-cal-cell-header-font-size` | `0.875rem` | `.z-cal table thead th` | `font-size` | Font size of the weekday headers. |
| `--z-cal-cell-hover-bg` | `var(--z-accent)` | `.z-cal table tbody tr td button:hover` | `background-color` | Background color of day buttons on hover. |
| `--z-cal-cell-hover-bg-o` | `var(--z-accent-o)` | `.z-cal table tbody tr td button:hover` | `background-color` | Opacity applied to the hover background color. |
| `--z-cal-cell-hover-color` | `var(--z-accent-f)` | `.z-cal table tbody tr td button:hover` | `color` | Text color of day buttons on hover. |
| `--z-cal-cell-hover-color-o` | `100%` | `.z-cal table tbody tr td button:hover` | `color` | Opacity applied to the hover text color. |
| `--z-cal-cell-oom-color` | `var(--z-muted-f)` | `.z-cal table tbody tr td.z-cal-oom button` | `color` | Text color of outside-month days. |
| `--z-cal-cell-oom-color-o` | `100%` | `.z-cal table tbody tr td.z-cal-oom button` | `color` | Opacity applied to the outside-month day text color. |
| `--z-cal-cell-padding` | `0` | `.z-cal table tbody tr td` | `padding` | Padding inside day cells. |
| `--z-cal-cell-radius` | `var(--z-global-radius)` | `.z-cal table tbody tr td` | `border-radius` | Corner radius of day cells. |
| `--z-cal-cell-size` | `2.5rem` | `.z-cal` | `height`, `max-width`, `width` | Width and height of each day cell; also constrains the calendar's max width. |
| `--z-cal-divider-cell-margin-bottom` | `0.25rem` | `.z-cal-divider table tbody tr td` | `margin-block-end` | Bottom margin of cells in the divider variant. |
| `--z-cal-divider-table-body-row-gap` | `0.25rem` | `.z-cal-divider table tbody` | `gap` | Row gap of the divider variant's body. |
| `--z-cal-divider-table-row-border-color` | `var(--z-border)` | `.z-cal-divider table tbody tr` | `border-color` | Row border color in the divider variant. |
| `--z-cal-divider-table-row-border-color-o` | `var(--z-border-o)` | `.z-cal-divider table tbody tr` | `border-color` | Opacity applied to divider row borders. |
| `--z-cal-divider-table-row-border-width` | `1px` | `.z-cal-divider table tbody tr` | `border-bottom-width` | Bottom border width of divider rows. |
| `--z-cal-header-column-gap` | `0.5rem` | `.z-cal-header` | `column-gap` | Gap between header items. |
| `--z-cal-hover-duration` | `150ms` | `.z-cal table tbody tr td button:hover` | `transition-duration` | Duration of the day-button hover transition. |
| `--z-cal-jumper-column-gap` | `0.5rem` | `.z-cal-jumper` | `column-gap` | Gap between jumper groups. |
| `--z-cal-jumper-input-width` | `3rem` | `.z-cal-jumper` | — | Width token for the jumper's year input; declared in the jumper scope but not consumed by any current rule. |
| `--z-cal-marked-bg` | `var(--z-info)` | `.z-cal-marked` | `background-color` | Background tint of marked cells. |
| `--z-cal-marked-bg-o` | `4%` | `.z-cal-marked` | `background-color` | Opacity applied to the marked-cell tint. |
| `--z-cal-marked-border-color` | `var(--z-info)` | `.z-cal-marked` | `border` | Border color of marked cells. |
| `--z-cal-marked-border-color-o` | `32%` | `.z-cal-marked` | `border` | Opacity applied to the marked-cell border color. |
| `--z-cal-marked-dot-color` | `var(--z-info)` | `.z-cal-marked` | `background-color` | Color of the marked-date indicator dot. |
| `--z-cal-marked-dot-color-o` | `100%` | `.z-cal-marked` | `background-color` | Opacity applied to the indicator dot color. |
| `--z-cal-marked-dot-offset` | `0.75rem` | `.z-cal-marked::after` | `transform` | Position offset of the marked-date indicator dot. |
| `--z-cal-marked-dot-size` | `0.25rem` | `.z-cal-marked` | `height`, `width` | Width and height of the indicator dot. |
| `--z-cal-table-body-row-gap` | `0.5rem` | `.z-cal table tbody` | `gap` | Gap between week rows. |
| `--z-cal-table-cell-gap` | `0.125rem` | `.z-cal table tbody tr, .z-cal table thead tr` | `gap` | Gap between cells within a row. |
| `--z-cal-table-row-gap` | `0.5rem` | `.z-cal table` | `gap` | Gap between the table's header and body sections. |
| `--z-cal-title-font-weight` | `500` | `.z-cal-title` | `font-weight` | Font weight of the month and year title. |

## i18n Keys

| Key | Default | Description |
| --- | --- | --- |
| `next-month` | `Next month` | Accessible label of the next-month button in the header and jumper. |
| `next-year` | `Next year` | Accessible label of the jumper's next-year button. |
| `prev-month` | `Previous month` | Accessible label of the previous-month button in the header and jumper. |
| `prev-year` | `Previous year` | Accessible label of the jumper's previous-year button. |
| `select-month` | `Select month` | Accessible label of the month dropdown. |
| `select-year` | `Select year` | Accessible label of the year input. |

## Icon Keys

| Key | Used in | Description |
| --- | --- | --- |
| `chevron-left` | `jumper-button`, `previous-button` | Icon on the previous-month and jumper stepper buttons. |
| `chevron-right` | `jumper-button`, `next-button` | Icon on the next-month and jumper stepper buttons. |

## Events

| Event | Cancelable | Detail | Description |
| --- | --- | --- | --- |
| `z-calendar:change` | — | `{ value: string \| string[] }` | Fires when the selected date changes; `detail.value` carries the ISO date string. |

## Data Hooks

| Attribute | Values | Applies to | Role | Description |
| --- | --- | --- | --- | --- |
| `data-host-inner` | — | `descendant` | `config` | Marks the rendered inner wrapper so `force-prevent-rerender` can adopt server-rendered DOM without re-rendering. |
| `data-iso` | — | `descendant` | `marker` | Full ISO timestamp bound to each day button; used for keyboard navigation and selection. |
| `data-reactive` | — | `descendant` | `config` | Opts the marked child (config script, data source, icons, or template) into live re-parsing when its DOM mutates. |

## Child Content

- `<script data-fn="config">` — JSON configuration script parsed by the base class (i18n, cls, stl, floating).

  | Attribute | Required | Type | Description |
  | --- | --- | --- | --- |
  | `data-fn` | ✓ | `config` | Marks the script as configuration (value: `config`). |
  | `data-reactive` | — | `boolean` | Re-parses the configuration when the script mutates. |

- `<select data-fn="data-source">` — Hidden select parsed into grouped option data by the base class.

  | Attribute | Required | Type | Description |
  | --- | --- | --- | --- |
  | `data-fn` | ✓ | `data-source` | Marks the select as the data source (value: `data-source`). |
  | `data-reactive` | — | `boolean` | Re-parses the options when the select mutates. |

  - `<optgroup>` — Groups options under a label.

    | Attribute | Required | Type | Description |
    | --- | --- | --- | --- |
    | `label` | ✓ | `string` | Group header text; also the default group key. |
    | `disabled` | — | `boolean` | Disables every option in the group. |
    | `data-key` | — | `string` | Overrides the group key used in the parsed data. |
    | `data-keywords` | — | `comma-separated string` | Comma-separated keywords stored with the group's data. |

    - `<option>` — One option entry within the group.

      | Attribute | Required | Type | Description |
      | --- | --- | --- | --- |
      | `value` | — | `string` | Value carried by this option in the parsed data. |
      | `disabled` | — | `boolean` | Makes the option non-selectable. |
      | `selected` | — | `boolean` | Marks the option as initially selected. |
      | `data-keywords` | — | `comma-separated string` | Extra search terms, comma-separated; searched alongside the label and value. |

  - `<option>` — One ungrouped option entry.

    | Attribute | Required | Type | Description |
    | --- | --- | --- | --- |
    | `value` | — | `string` | Value carried by this option in the parsed data. |
    | `disabled` | — | `boolean` | Makes the option non-selectable. |
    | `selected` | — | `boolean` | Marks the option as initially selected. |
    | `data-keywords` | — | `comma-separated string` | Extra search terms, comma-separated. |

- `<template data-fn="icons">` — Instance-level icon repository.

  | Attribute | Required | Type | Description |
  | --- | --- | --- | --- |
  | `data-fn` | ✓ | `icons` | Marks the template as an icon source (value: `icons`). |
  | `data-reactive` | — | `boolean` | Re-parses the icons when the template mutates. |

  - `<*>` — One icon element.

    | Attribute | Required | Type | Description |
    | --- | --- | --- | --- |
    | `data-key` | ✓ | `string` | Icon key referenced by `$icons`. |

- `<template data-fn="template">` — Deferred content template mounted by the base class.

  | Attribute | Required | Type | Description |
  | --- | --- | --- | --- |
  | `data-fn` | ✓ | `template` | Marks the template for deferred mounting (value: `template`). |
  | `data-reactive` | — | `boolean` | Re-parses the template when it mutates. |

## CSS Classes

| Class | Role | Applies to | Description |
| --- | --- | --- | --- |
| `.z-active` | `state` | `.z-cal` | State class on the selected day cell. |
| `.z-cal` | `root` | `z-calendar` | Root calendar class. |
| `.z-cal-divider` | `modifier` | `.z-cal` | Modifier that switches the grid to a divided, row-separated layout. |
| `.z-cal-header` | `element` | `.z-cal` | Header bar layout (flex row). |
| `.z-cal-header-l` | `element` | `.z-cal` | Left header group that keeps its natural width. |
| `.z-cal-header-r` | `element` | `.z-cal` | Right header group that keeps its natural width. |
| `.z-cal-jumper` | `element` | `.z-cal` | Jumper layout container. |
| `.z-cal-jumper-month` | `element` | `.z-cal` | Month group layout. |
| `.z-cal-jumper-year` | `element` | `.z-cal` | Year group layout. |
| `.z-cal-marked` | `state` | `.z-cal` | State class on marked day cells; renders the indicator dot. |
| `.z-cal-oom` | `state` | `.z-cal` | State class on outside-month day cells (muted). |
| `.z-cal-title` | `element` | `.z-cal` | Month and year title styling. |

## Keyboard

| Keys | Action | When |
| --- | --- | --- |
| `ArrowLeft` / `ArrowRight` | Move focus to the previous / next enabled day. | Focus is on a day button |
| `ArrowUp` / `ArrowDown` | Move focus to the same weekday in the previous / next week, skipping disabled days. | Focus is on a day button |
| `Home` / `End` | Move focus to the first / last enabled day of the week. | Focus is on a day button |
| `PageUp` / `PageDown` | Step to the previous / next month. | Focus is on a day button |
| `Ctrl+PageUp` / `Ctrl+PageDown` / `Meta+PageUp` / `Meta+PageDown` | Step to the previous / next year. | Focus is on a day button |
| `Enter` / ` ` | Select the focused day. | Focus is on a day button |

## Accessibility

| Part | Attributes | Description |
| --- | --- | --- |
| `day` | `aria-selected="dynamic"`, `role="gridcell"` | Day cell (gridcell) whose `aria-selected` reflects selection. |
| `day-button` | `aria-disabled="dynamic"`, `aria-label="dynamic"`, `aria-pressed="dynamic"` | Day button with a full-date aria-label, `aria-pressed` for selection, and `aria-disabled` for unavailable dates. |
| `header` | — | Month navigation bar. |
| `host-inner` | `aria-label="Calendar"`, `role="application"` | Calendar root with `role="application"` and a static aria-label. |
| `jumper` | — | Jumper container. |
| `jumper-button` | `aria-label="dynamic"` | Stepper button labelled by the prev/next month or year i18n text. |
| `jumper-month` | — | Month stepper group. |
| `jumper-year` | — | Year stepper group. |
| `month-select` | `aria-label="dynamic"` | Month dropdown labelled by `select-month`. |
| `next-button` | `aria-label="dynamic"` | Next-month button labelled by `next-month`. |
| `previous-button` | `aria-label="dynamic"` | Previous-month button labelled by `prev-month`. |
| `title` | — | Month and year title container. |
| `week` | `role="row"` | Week row (`role="row"`). |
| `weekday` | `role="columnheader"` | Weekday header cell (`role="columnheader"`). |
| `year-input` | `aria-label="dynamic"` | Year input labelled by `select-year`. |

> Roving tabindex: only the selected day (or today when nothing is selected) is tabbable; arrow keys move focus within the grid.

> The grid combines `role="application"` on the root with grid, row, columnheader, and gridcell semantics.

## Notes

- Dates are parsed and emitted in UTC (YYYY-MM-DD) to prevent timezone off-by-one shifts.
- Selecting an outside-month day steps the view to that month.

## Guides

- [Styling with cls and stl](https://next.0build.dev/docs/guides/styling.md)
- [Translating Components](https://next.0build.dev/docs/guides/i18n.md)
- [Icon Resolution](https://next.0build.dev/docs/guides/icons.md)
- [The data-source Convention](https://next.0build.dev/docs/guides/data-source.md)
- [Openers & Triggers](https://next.0build.dev/docs/guides/triggers.md)
- [Dialog Behavior](https://next.0build.dev/docs/guides/dialogs.md)
- [Utilities](https://next.0build.dev/docs/guides/utilities.md)
- [Runtime](https://next.0build.dev/docs/guides/runtime.md)
