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.

Preview

No preview output yet.

live.tsxReady

Range

Start and end dates with in-range highlighting.

Preview

No preview output yet.

live.tsxReady

Manual grid

Compose Calendar.Row and Calendar.Cell with Grid.Head and Grid.Body for full control over the matrix.

Preview

No preview output yet.

live.tsxReady

Dual range

Two-month layout with a shared range selection model.

Preview

No preview output yet.

live.tsxReady

Month and year selectors

Replace static month and year labels with Select-driven controls wired to calendar context.

Preview

No preview output yet.

live.tsxReady

Anatomy

tsx
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.

PropTypeDefault
asChild
booleanfalse
daysInWeek*
Record<string, string>—
mode
"single" | "range" | "dual-range""single"
defaultDates
Date[][]
selectedDates
Date[]—
onValueChange
(dates: Date[]) => void—
visibleMonth
Date—
onVisibleMonthChange
(date: Date) => void—
AttributeValues
[data-slot]"calendar-root"

HeaderPrevious

Previous-month button routed through the shared month setter. Retains native button props/ref and default type="button".

PropTypeDefault
asChild
booleanfalse
disabled
booleanfalse
AttributeValues
[data-slot]"calendar-header-previous"

HeaderNext

Next-month button routed through the shared month setter. Retains native button props/ref and default type="button".

PropTypeDefault
asChild
booleanfalse
disabled
booleanfalse
AttributeValues
[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.

PropTypeDefault
asChild
booleanfalse
AttributeValues
[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.

PropTypeDefault
asChild
booleanfalse
AttributeValues
[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.

AttributeValues
[data-slot]"calendar-body"

Rows

Grid.Body delegate; defaults to tbody beneath the generated table. Preserve native table ancestry.

PropTypeDefault
asChild
booleanfalse

DayHeader

Grid.Header delegate; defaults to th under a row and applies the calendar dayHeader class hook.

PropTypeDefault
asChild
booleanfalse

Row

Existing Grid.Row delegate; defaults to tr under thead or tbody. Contains native th or td cells.

PropTypeDefault
asChild
booleanfalse

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.

PropTypeDefault
asChild
booleanfalse
date*
Date—
isOutsideMonth
booleanfalse
AttributeValues
[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.

PropTypeDefault
open
boolean—
defaultOpen
booleanfalse

YearSelect

Generated year Select composition with a native button trigger ref. Uses the calendar year setter; does not expose asChild.

PropTypeDefault
years
number[]—
open
boolean—

Keyboard

ShortcutAction
→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.
HomeMove focus to the first day of the current week.
EndMove focus to the last day of the current week.
Enter/SpaceSelect the focused date.
PageDownMove the calendar forward one month.
PageUpMove the calendar back one month.
Shift+PageDownMove the calendar forward one year.
Shift+PageUpMove 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.

Previous
Button Group
Next
Card