# Calendar

A month grid to pick a date, several dates or a range.

A month grid to pick a date, several dates or a range, shown inline. A header with the pager's previous and next buttons around the month, which switches to a month and then a year view; seven columns of days, six weeks so the grid never changes height. The selected date is filled with ink, the hovered one takes the hover colour, today carries a dot. Arrow keys, Page Up / Down, Home and End move through the days at once. Behaviour, focus and ARIA come from the Zag date-picker machine, through Ark UI. The date picker shows the same views in its popup.

Kind: component · Category: Inputs · Status: beta · Targets: React, Vue, Svelte · Behaviour: Zag `date-picker` machine, through Ark UI

## Add

```bash
npx fndn add calendar
```

It writes the folder `calendar/` into the project's ui folder (`index.ts`, `calendar.tsx`, `Calendar.vue`, `Calendar.svelte`, `calendar.recipe.ts`), and what it is built from: [Button](/components/button.md), [Tooltip](/components/tooltip.md). First time: [Installation](/installation.md).

## Usage

```tsx
import { Calendar } from "@/components/ui/calendar";
```

```vue
import { Calendar } from "@/components/ui/calendar";
```

```svelte
import { Calendar } from "$lib/components/ui/calendar";
```

## Parts

In the DOM the root carries `data-slot="calendar"` and each part `data-slot="calendar-<part>"`; in the recipe the root is the `base` slot and each part a slot named after it in camelCase.

| Part | Element | data-slot | Flags | Notes |
| --- | --- | --- | --- | --- |
| `root` | `div` | `calendar` |  | The engine's root, inline. data-disabled at half opacity. |
| `content` | `div` | `calendar-content` |  | The engine's content element: role=application, named by the caller's aria-label; it holds the views (the engine finds the focused date inside it). In the date picker, its popup is this element. |
| `view` | `div` | `calendar-view` | repeats | One per view (day, month, year); the engine hides all but the current one. 224px wide (280px on coarse pointers), the same size in every view and every month. |
| `header` | `div` | `calendar-header` |  | prev · title · next, spread across the view (the pager's between layout). |
| `prev` | `button` | `calendar-prev` |  | The real Button (ghost, sm, square, muted), marked data-calendar="prev", with a Tooltip and an aria-label naming what it pages (Previous month / year / decade). Disabled by the engine past min. The caret mirrors right-to-left. |
| `title` | `button` | `calendar-title` |  | A ghost sm Button, marked data-calendar="title": the month and year (day view), the year (month view), the decade (year view), xs medium ink. Switches to the next view up; disabled in the year view, where it reads as plain text. |
| `next` | `button` | `calendar-next` |  | As prev, marked data-calendar="next". |
| `grid` | `table` | `calendar-grid` |  | role=grid labelled with the visible month; keyboard handling lives here. Months and years fill the day grid's height (216px, 264px on coarse pointers). |
| `head` | `thead` | `calendar-head` |  | aria-hidden (every date's label says its weekday). |
| `weekday` | `th` | `calendar-weekday` | repeats | Short weekday name in the locale: 2xs, ink-2, 24px high. |
| `body` | `tbody` | `calendar-body` |  |  |
| `row` | `tr` | `calendar-row` | repeats |  |
| `cell` | `td` | `calendar-cell` | repeats | role=gridcell, aria-selected, aria-current=date on today. Carries the range band (color.hover-2), rounded at the range's ends and at the ends of each week; color.hover while the second end is being chosen. |
| `cell-trigger` | `div` | `calendar-cell-trigger` | repeats | role=button, the date (or month, or year): 32px square, 40px on coarse pointers; a 40px-high full-width row in the month and year views. data-selected: ink fill, on-ink text, weight 500. data-today: a 4px dot under the number. data-outside-range (the other month's days): ink-3, not selectable. data-unavailable: ink-3, struck through. Hover: color.hover. |

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `value` | `string[]` |  | Bindable (React: `defaultValue` and `onValueChange`; Vue: `v-model:value`; Svelte: `bind:value`). Selected dates as ISO strings ("2025-03-12"). single: one; range: the start and the end. |
| `selectionMode` | `"single" \| "multiple" \| "range"` | `"single"` |  |
| `min` | `string` |  | Earliest date that can be chosen (ISO). Paging stops at its month. |
| `max` | `string` |  | Latest date that can be chosen (ISO). |
| `unavailable` | `string[]` |  | Dates that cannot be chosen (ISO). Also takes isDateUnavailable(date). |
| `defaultFocusedValue` | `string` |  | The date the calendar opens on when no value is set (its month is shown; the keyboard starts there). Without it: today. |
| `startOfWeek` | `number` |  | 0 Sunday … 6 Saturday. Without it: the locale's. |
| `locale` | `string` |  | BCP 47 tag for the names and digits. Without it: the LocaleProvider's. |
| `timeZone` | `string` |  | Where "today" is taken. Without it: the browser's. |
| `fixedWeeks` | `boolean` | `true` | Always six weeks, so the grid keeps its height from month to month. |
| `disabled` | `boolean` | `false` |  |
| `readOnly` | `boolean` | `false` |  |

Other attributes and `class` go to the root; `class` is merged through the recipe.

## Events

| Event | Payload |
| --- | --- |
| `valueChange` | (value: string[]) ISO dates |

## States

`hover`, `press`, `focus-visible`, `selected`, `today`, `in-range`, `outside-month`, `unavailable`, `disabled`

## Keyboard and accessibility

Role: application + grid.

Keyboard:

- Tab reaches previous, the title, next, then the focused date of the grid (one tab stop)
- ArrowLeft / ArrowRight move one day (swapped right-to-left), ArrowUp / ArrowDown one week; past the edge the month changes
- Page Up / Page Down move one month (Shift: one year); in the month and year views, one year and one decade
- Home / End move to the first and the last day of the month (the first and last month or year in the other views)
- Enter / Space choose the focused date; in the month and year views they open that month or year
- Every move is instant: the focus ring jumps, nothing slides. The ring is drawn inside the date (the dates touch), never over its neighbour

Notes:

- Give the calendar an aria-label. Each date is labelled with its full date and its state (Selected date, In range, Not available); the grid with the visible month.
- Today is marked by a dot and aria-current="date", not by colour alone; selected dates by an ink fill and aria-selected.
- The previous and next buttons have tooltips and aria-labels naming the step; the title's name is its visible text.

## Motion

- dates: hover and selection colour over duration.fast; instant from the keyboard (kbd-instant)
- range band: the cell's colour changes with the dates it holds, over duration.fast; instant from the keyboard
- press: a date scales by motion.press-scale over duration.press, from the pointer only
- paging, switching views, moving focus: instant; nothing slides or fades
- header buttons: the Button's own hover and press

## Tokens

`color.hover`, `color.hover-2`, `color.ink`, `color.ink-2`, `color.ink-3`, `color.on-ink`, `radius.chip`, `text.2xs`, `text.sm`, `duration.fast`, `duration.press`, `easing.out-strong`, `motion.press-scale`

## Dependencies

- [Button](/components/button.md)
- [Tooltip](/components/tooltip.md)

## Examples

### A date

React · `single.tsx`

```tsx
import { Calendar } from "@/components/ui/calendar";

export default function Single() {
  return <Calendar aria-label="Delivery date" defaultValue={["2026-12-12"]} />;
}
```

Vue · `single.vue`

```vue
<script setup lang="ts">
import { Calendar } from "@/components/ui/calendar";
</script>

<template>
  <Calendar aria-label="Delivery date" :defaultValue="['2026-12-12']" />
</template>
```

Svelte · `single.svelte`

```svelte
<script lang="ts">
  import { Calendar } from "$lib/components/ui/calendar";
</script>

<Calendar aria-label="Delivery date" defaultValue={["2026-12-12"]} />
```

### A range

React · `range.tsx`

```tsx
import { Calendar } from "@/components/ui/calendar";

export default function Range() {
  return <Calendar aria-label="Stay" selectionMode="range" defaultValue={["2026-12-10", "2026-12-14"]} />;
}
```

Vue · `range.vue`

```vue
<script setup lang="ts">
import { Calendar } from "@/components/ui/calendar";
</script>

<template>
  <Calendar aria-label="Stay" selectionMode="range" :defaultValue="['2026-12-10', '2026-12-14']" />
</template>
```

Svelte · `range.svelte`

```svelte
<script lang="ts">
  import { Calendar } from "$lib/components/ui/calendar";
</script>

<Calendar aria-label="Stay" selectionMode="range" defaultValue={["2026-12-10", "2026-12-14"]} />
```

### Min, max and unavailable days

React · `limits.tsx`

```tsx
import { Calendar } from "@/components/ui/calendar";

/* weekends and two holidays cannot be booked; nothing before the 3rd or after the 28th */
const weekend = (date: string) => [0, 6].includes(new Date(`${date}T12:00:00Z`).getUTCDay());

export default function Limits() {
  return (
    <Calendar
      aria-label="Appointment"
      defaultFocusedValue="2026-12-01"
      min="2026-12-01"
      max="2026-12-23"
      unavailable={["2026-12-09", "2026-12-16"]}
      isDateUnavailable={weekend}
    />
  );
}
```

Vue · `limits.vue`

```vue
<script setup lang="ts">
import { Calendar } from "@/components/ui/calendar";

/* weekends and two holidays cannot be booked; nothing before the 3rd or after the 28th */
const weekend = (date: string) => [0, 6].includes(new Date(`${date}T12:00:00Z`).getUTCDay());
</script>

<template>
  <Calendar
    aria-label="Appointment"
    defaultFocusedValue="2026-12-01"
    min="2026-12-01"
    max="2026-12-23"
    :unavailable="['2026-12-14', '2026-12-21']"
    :isDateUnavailable="weekend"
  />
</template>
```

Svelte · `limits.svelte`

```svelte
<script lang="ts">
  import { Calendar } from "$lib/components/ui/calendar";

  /* weekends and two holidays cannot be booked; nothing before the 3rd or after the 28th */
  const weekend = (date: string) => [0, 6].includes(new Date(`${date}T12:00:00Z`).getUTCDay());
</script>

<Calendar
  aria-label="Appointment"
  defaultFocusedValue="2026-12-01"
  min="2026-12-01"
  max="2026-12-23"
  unavailable={["2026-12-09", "2026-12-16"]}
  isDateUnavailable={weekend}
/>
```

### Week start and locale

React · `locale.tsx`

```tsx
import { Calendar } from "@/components/ui/calendar";

export default function Locale() {
  return <Calendar aria-label="Liefertermin" locale="de-DE" startOfWeek={1} defaultValue={["2026-12-12"]} />;
}
```

Vue · `locale.vue`

```vue
<script setup lang="ts">
import { Calendar } from "@/components/ui/calendar";
</script>

<template>
  <Calendar aria-label="Liefertermin" locale="de-DE" :startOfWeek="1" :defaultValue="['2026-12-12']" />
</template>
```

Svelte · `locale.svelte`

```svelte
<script lang="ts">
  import { Calendar } from "$lib/components/ui/calendar";
</script>

<Calendar aria-label="Liefertermin" locale="de-DE" startOfWeek={1} defaultValue={["2026-12-12"]} />
```

### Pick a delivery date

React · `delivery-date.tsx`

```tsx
import { useState } from "react";
import { Calendar } from "@/components/ui/calendar";

export default function DeliveryDate() {
  const [dates, setDates] = useState<string[]>(["2026-12-12"]);
  return (
    <div className="flex flex-col gap-2">
      <Calendar aria-label="Delivery date" value={dates} onValueChange={setDates} />
      <span className="text-sm text-ink-2">{dates[0] ? `Delivery on ${dates[0]}.` : "No date chosen."}</span>
    </div>
  );
}
```

Vue · `delivery-date.vue`

```vue
<script setup lang="ts">
import { ref } from "vue";
import { Calendar } from "@/components/ui/calendar";

const dates = ref<string[]>(["2026-12-12"]);
</script>

<template>
  <div class="flex flex-col gap-2">
    <Calendar aria-label="Delivery date" v-model:value="dates" />
    <span class="text-sm text-ink-2">{{ dates[0] ? `Delivery on ${dates[0]}.` : "No date chosen." }}</span>
  </div>
</template>
```

Svelte · `delivery-date.svelte`

```svelte
<script lang="ts">
  import { Calendar } from "$lib/components/ui/calendar";

  let dates = $state<string[]>(["2026-12-12"]);
</script>

<div class="flex flex-col gap-2">
  <Calendar aria-label="Delivery date" bind:value={dates} />
  <span class="text-sm text-ink-2">{dates[0] ? `Delivery on ${dates[0]}.` : "No date chosen."}</span>
</div>
```

## Recipe

`calendar.recipe.ts`:

```ts
import { tv, type VariantProps } from "../lib/tv";

/* calendar — a month grid on the Zag date-picker machine (through Ark UI), shown on its own
 * (inline) or inside the date picker's popup. Three views share one box: days (7 columns, six
 * weeks), months and years (4 columns). The box keeps one size across months and views, so
 * paging never moves what sits around it: 224px wide (seven 32px days), the day grid 24px of
 * weekday names plus six 32px weeks; on coarse pointers 40px days.
 *
 * Header: the pager's controls: previous and next are the real Button (ghost, sm, square, muted),
 * marked data-calendar="prev|next"; the title between them is a ghost Button too (data-calendar=
 * "title"), which switches to the month, then the year view. The carets mirror right-to-left.
 *
 * A date (the cell trigger, written by the engine: data-selected, data-today, data-in-range,
 * data-outside-range, data-unavailable, data-disabled, data-focus):
 *   hover          color.hover (gated to a real pointer)
 *   selected       ink fill, on-ink text: never the hover's colour
 *   range          the band (color.hover-2) is painted on the cell behind the dates, rounded at the
 *                  range's ends and at the ends of each week; its two ends are selected dates.
 *                  While the second end is being chosen, the band under the pointer is color.hover.
 *                  The band changes colour over duration.fast, as the dates do.
 *   today          a 4px dot under the number (a shape, not a colour), aria-current="date"
 *   other month    ink-3, not selectable
 *   unavailable    ink-3 and struck through (min / max, and the caller's unavailable days)
 *   focus          the global focus ring (base.css), drawn inside the date (the dates touch, as a
 *                  table's cells do); arrow keys move it at once
 * A press scales the date from the pointer only; Space and Enter act at once (kbd-instant).
 * Paging and switching views are instant: nothing slides. */

export const calendar = tv({
  slots: {
    base: "inline-flex flex-col min-w-0 max-w-full data-disabled:opacity-50",
    /* the engine's content element (role=application, named by the calendar's aria-label); in the
     * date picker, the popup is this element */
    content: "outline-none",
    /* one view at a time (the engine sets hidden on the others) */
    view: "flex flex-col gap-2 w-56 pointer-coarse:w-70 [&[hidden]]:hidden",
    header: "flex items-center justify-between gap-1",
    /* passed to the Buttons as className, after their own classes */
    prev: "[&:dir(rtl)_[data-slot=icon]]:[transform:scaleX(-1)]",
    next: "[&:dir(rtl)_[data-slot=icon]]:[transform:scaleX(-1)]",
    /* the month is the heading: sm / medium ink. In the year view there is no further view, so
     * the engine disables it; it then reads as plain text, not as a half-faded control */
    title: "min-w-0 text-sm font-medium [unicode-bidi:isolate] disabled:opacity-100",
    grid: [
      "w-full table-fixed border-separate border-spacing-0 outline-none",
      /* months and years fill the day grid's height */
      "data-[view=month]:h-[216px] data-[view=year]:h-[216px]",
      "pointer-coarse:data-[view=month]:h-[264px] pointer-coarse:data-[view=year]:h-[264px]",
    ],
    head: "",
    weekday: "h-6 p-0 text-center align-middle text-2xs font-normal text-ink-2 whitespace-nowrap",
    body: "",
    row: "",
    /* the cell carries the range band, so it runs unbroken from one end to the other; the band
     * changes colour with the dates it holds (duration.fast), at once from the keyboard */
    cell: [
      "kbd-instant",
      "p-0 text-center align-middle motion-colors-fast",
      "first:rounded-s-chip last:rounded-e-chip",
      "[&:has(>[data-in-range]:not([data-in-hover-range]))]:bg-hover-2 [&:has(>[data-in-hover-range])]:bg-hover",
      "[&:has(>[data-range-start])]:rounded-s-chip [&:has(>[data-range-end])]:rounded-e-chip",
      "[&:has(>[data-hover-range-start])]:rounded-s-chip [&:has(>[data-hover-range-end])]:rounded-e-chip",
    ],
    cellTrigger: [
      "kbd-instant",
      "relative flex items-center justify-center mx-auto size-8 pointer-coarse:size-10 rounded-chip",
      "text-dense leading-none text-ink tabular-nums cursor-pointer select-none",
      "data-[view=month]:w-full data-[view=month]:h-10 data-[view=year]:w-full data-[view=year]:h-10",
      "motion-colors-fast motion-transform-press [:root:not([data-fndn-input=keyboard])_&:active]:scale-press",
      /* dates touch: the ring is drawn inside the date, as on a table's cells, never over its neighbour */
      "focus-visible:-outline-offset-2",
      "hover:bg-hover",
      "data-selected:bg-ink data-selected:text-on-ink data-selected:font-medium hover:data-selected:bg-ink",
      /* today: a dot under the number, in the number's colour */
      "data-today:after:absolute data-today:after:inset-x-0 data-today:after:bottom-1 data-today:after:mx-auto data-today:after:size-1 data-today:after:rounded-full data-today:after:bg-current",
      "data-outside-range:text-ink-3",
      "data-unavailable:text-ink-3 data-unavailable:line-through",
      "data-disabled:cursor-default data-disabled:pointer-events-none",
    ],
  },
});

export type CalendarRecipeProps = VariantProps<typeof calendar>;
```
