Calendar
A grid-backed calendar for single-date and range selection with keyboard navigation and selection modes.
Features
- Multiple selection modes
- Grid-backed structure
- Controlled or uncontrolled
- Extensible header
- Rich date state
- Keyboard navigation
Installation
npm install @ariaui/calendar
Examples
Each playground is a self-contained example: single date, range, manual grid composition, dual-range two-pane layout, and month/year Select controls in the header.
Styling uses semantic tokens (border-border, bg-card, text-foreground, etc.) and lucide-react icons. Snippets for the manual grid interpolate the same class strings as the live preview.
Single date
One selected day with header navigation and manual-grid styling.
No preview output yet.
Range
Start and end dates with in-range highlighting.
No preview output yet.
Manual grid
Compose Calendar.Row and Calendar.Cell with Grid.Head and Grid.Body for full control over the matrix.
No preview output yet.
Dual range
Two-month layout with a shared range selection model.
No preview output yet.
Month and year selectors
Replace static month and year labels with Select-driven controls wired to calendar context.
No preview output yet.
Anatomy
import * as Calendar from "@ariaui/calendar";
export default function Example() {
return (
<Calendar.Root>
<Calendar.Header>
<Calendar.HeaderPrevious />
<Calendar.HeaderMonth />
<Calendar.HeaderYear />
<Calendar.MonthSelect />
<Calendar.YearSelect />
<Calendar.HeaderNext />
</Calendar.Header>
<Calendar.Body>
<Calendar.Head>
<Calendar.Row>
<Calendar.DayHeader />
</Calendar.Row>
</Calendar.Head>
<Calendar.Rows>
<Calendar.Row>
<Calendar.Cell />
</Calendar.Row>
</Calendar.Rows>
</Calendar.Body>
</Calendar.Root>
);
}
API Reference
Root
Owns calendar selection, visible month, mode and descendant context. Defaults to a div; its state and focus providers remain outside an adopted host.
| Prop | Type | Default |
|---|---|---|
asChild | boolean | false |
daysInWeek* | Record<string, string> | — |
mode | "single" | "range" | "dual-range" | "single" |
defaultDates | Date[] | [] |
selectedDates | Date[] | — |
onValueChange | (dates: Date[]) => void | — |
visibleMonth | Date | — |
onVisibleMonthChange | (date: Date) => void | — |
| Attribute | Values |
|---|---|
| [data-slot] | "calendar-root" |
Header
Defaults to a div. Normal nullish children generate previous/next buttons and month/year labels; an adopted host owns its explicit content.
| Prop | Type | Default |
|---|---|---|
asChild | boolean | false |
| Attribute | Values |
|---|---|
| [data-slot] | "calendar-header" |
HeaderPrevious
Previous-month button routed through the shared month setter. Retains native button props/ref and default type="button".
| Prop | Type | Default |
|---|---|---|
asChild | boolean | false |
disabled | boolean | false |
| Attribute | Values |
|---|---|
| [data-slot] | "calendar-header-previous" |
HeaderNext
Next-month button routed through the shared month setter. Retains native button props/ref and default type="button".
| Prop | Type | Default |
|---|---|---|
asChild | boolean | false |
disabled | boolean | false |
| Attribute | Values |
|---|---|
| [data-slot] | "calendar-header-next" |
HeaderMonth
Defaults to a span. Normal nullish children show the visible month; an adopted child owns its text, including empty content.
| Prop | Type | Default |
|---|---|---|
asChild | boolean | false |
| Attribute | Values |
|---|---|
| [data-slot] | "calendar-header-month" |
HeaderYear
Defaults to a span. Normal nullish children show the visible year; an adopted child owns its text, including empty content.
| Prop | Type | Default |
|---|---|---|
asChild | boolean | false |
| Attribute | Values |
|---|---|
| [data-slot] | "calendar-header-year" |
Body
Generated div/grid boundary. With no custom children, builds the weekday headings and six-week month grid, or both panes in dual-range mode. Custom children remain inside its Grid.Root. Does not expose asChild.
| Attribute | Values |
|---|---|
| [data-slot] | "calendar-body" |
Head
Grid.Head delegate; defaults to thead beneath the generated table. Preserve native table ancestry.
| Prop | Type | Default |
|---|---|---|
asChild | boolean | false |
Rows
Grid.Body delegate; defaults to tbody beneath the generated table. Preserve native table ancestry.
| Prop | Type | Default |
|---|---|---|
asChild | boolean | false |
DayHeader
Grid.Header delegate; defaults to th under a row and applies the calendar dayHeader class hook.
| Prop | Type | Default |
|---|---|---|
asChild | boolean | false |
Row
Existing Grid.Row delegate; defaults to tr under thead or tbody. Contains native th or td cells.
| Prop | Type | Default |
|---|---|---|
asChild | boolean | false |
Cell
Grid.Cell-backed date cell. Defaults to td with a generated inner date div; adopted td keeps outer calendar state while custom content owns inner presentation.
| Prop | Type | Default |
|---|---|---|
asChild | boolean | false |
date* | Date | — |
isOutsideMonth | boolean | false |
| Attribute | Values |
|---|---|
| [data-slot] | "calendar-cell" (outer); "calendar-cell-inner" (generated inner only) |
| [data-selected] | Present when selected |
| [data-today] | Present for today |
| [data-outside-month] | Present for an outside-month date |
| [data-range-start] | "true" at the range start |
| [data-range-end] | "true" at the range end |
| [data-in-range] | Present within the committed range, including endpoints |
MonthSelect
Generated month Select composition with a native button trigger ref. Uses the calendar month setter; does not expose asChild.
| Prop | Type | Default |
|---|---|---|
open | boolean | — |
defaultOpen | boolean | false |
YearSelect
Generated year Select composition with a native button trigger ref. Uses the calendar year setter; does not expose asChild.
| Prop | Type | Default |
|---|---|---|
years | number[] | — |
open | boolean | — |
Keyboard
| Shortcut | Action |
|---|---|
| → | Move focus to the next day. Crossing a week or month boundary updates the visible month. |
| ← | Move focus to the previous day. Crossing a week or month boundary updates the visible month. |
| ↓ | Move focus to the same day of the next week. |
| ↑ | Move focus to the same day of the previous week. |
| Home | Move focus to the first day of the current week. |
| End | Move focus to the last day of the current week. |
| Enter/Space | Select the focused date. |
| PageDown | Move the calendar forward one month. |
| PageUp | Move the calendar back one month. |
| Shift+PageDown | Move the calendar forward one year. |
| Shift+PageUp | Move the calendar back one year. |
Grid cell focus automatically updates the visible month when navigating across boundaries, and day-number fallback is applied when jumping to a month that lacks the target day.
Accessibility
The Calendar component implements the WAI-ARIA Date Picker Dialog pattern. Date cells use a grid structure with proper ARIA attributes:
[aria-selected="true"]marks the selected date(s)[aria-disabled="true"]marks dates outside the visible month[data-today]identifies the current date for visual distinction- Range mode exposes
[data-range-start],[data-range-end], and[data-in-range]for styling range spans
Each date cell is keyboard-focusable and selectable via Enter/Space. Month/year navigation is exposed in the header via buttons with accessible labels.