Skip to content

Calendar

Shows a month grid so people can pick a date, several dates or a range of dates.

Delivery date, November 2026

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5

Installation

pnpm dlx shadcn@latest add @silkware/calendar

To copy the component by hand, install its dependencies:

pnpm add react-aria-components class-variance-authority cn lucide-react

Then copy the source into components/ui/calendar.tsx. It also needs Button and Select, used by the month and year dropdowns:

components/ui/calendar.tsx
"use client"
import * as React from "react"import { cva } from "class-variance-authority"import { cn } from "cn"import {  Calendar as AriaCalendar,  CalendarGridHeader as AriaCalendarGridHeader,  RangeCalendar as AriaRangeCalendar,  CalendarCell,  CalendarGrid,  CalendarGridBody,  CalendarHeaderCell,  CalendarHeading,  CalendarMonthPicker,  CalendarYearPicker,  type CalendarCellRenderProps,  type CalendarProps,  type DateValue,  type RangeCalendarProps,} from "react-aria-components"
import { Button, buttonVariants } from "@/components/ui/button"import {  Select,  SelectContent,  SelectGroup,  SelectItem,  SelectTrigger,  SelectValue,} from "@/components/ui/select"import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react"
const cellVariants = cva(  "group/day relative mt-2 aspect-square h-full w-full cursor-default rounded-(--cell-radius) p-0 text-center select-none [&:is(:last-child>[data-selected=true])>div]:rounded-r-(--cell-radius)",  {    variants: {      showWeekNumber: {        false:          "[&:is(:first-child>[data-selected=true])>div]:rounded-l-(--cell-radius)",        true: "[&:is(:nth-child(2)>[data-selected=true])>div]:rounded-l-(--cell-radius)",      },      isToday: {        true: "rounded-(--cell-radius) bg-muted text-foreground data-[selected=true]:rounded-none",      },      isSelectionStart: {        true: "relative isolate z-0 rounded-l-(--cell-radius) bg-muted after:absolute after:inset-y-0 after:right-0 after:w-4 after:bg-muted",      },      isSelectionEnd: {        true: "relative isolate z-0 rounded-r-(--cell-radius) bg-muted after:absolute after:inset-y-0 after:left-0 after:w-4 after:bg-muted",      },      isUnavailable: {        true: "text-muted-foreground opacity-50 [&>div]:line-through",      },      isDisabled: {        true: "text-muted-foreground opacity-50",      },      isOutsideMonth: {        true: "text-muted-foreground aria-selected:text-muted-foreground",      },    },  })
function Calendar<  T extends DateValue,  M extends "single" | "multiple" = "single",>(  props: Omit<CalendarProps<T, M>, "visibleDuration"> & {    buttonVariant?: React.ComponentProps<typeof Button>["variant"]    captionLayout?: "label" | "dropdown"    numberOfMonths?: number    showWeekNumber?: boolean    headerFormat?: Intl.DateTimeFormatOptions    renderCell?: (      renderProps: CalendarCellRenderProps & {        defaultChildren: React.ReactNode      }    ) => React.ReactNode  }) {  return (    <AriaCalendar      {...props}      data-slot="calendar"      visibleDuration={{ months: props.numberOfMonths || 1 }}      className={cn(        "group/calendar w-fit bg-background p-3 [--cell-radius:var(--radius-md)] [--cell-size:--spacing(8)] in-data-[slot=card-content]:bg-transparent in-data-[slot=popover-content]:bg-transparent",        props.className      )}    >      <CalendarInner {...props} />    </AriaCalendar>  )}
function RangeCalendar<T extends DateValue>(  props: RangeCalendarProps<T> & {    buttonVariant?: React.ComponentProps<typeof Button>["variant"]    captionLayout?: "label" | "dropdown"    headerFormat?: Intl.DateTimeFormatOptions    numberOfMonths?: number    showWeekNumber?: boolean    renderCell?: (      renderProps: CalendarCellRenderProps & {        defaultChildren: React.ReactNode      }    ) => React.ReactNode  }) {  return (    <AriaRangeCalendar      {...props}      data-slot="calendar"      visibleDuration={{ months: props.numberOfMonths || 1 }}      className={cn(        "group/calendar w-fit bg-background p-3 [--cell-radius:var(--radius-md)] [--cell-size:--spacing(8)] in-data-[slot=card-content]:bg-transparent in-data-[slot=popover-content]:bg-transparent",        props.className      )}    >      <CalendarInner {...props} isRange />    </AriaRangeCalendar>  )}
function CalendarInner({  captionLayout = "label",  buttonVariant = "ghost",  numberOfMonths = 1,  showWeekNumber = false,  headerFormat,  renderCell,  isRange,}: {  buttonVariant?: React.ComponentProps<typeof Button>["variant"]  captionLayout?: "label" | "dropdown"  numberOfMonths?: number  showWeekNumber?: boolean  headerFormat?: Intl.DateTimeFormatOptions  renderCell?: (    renderProps: CalendarCellRenderProps & { defaultChildren: React.ReactNode }  ) => React.ReactNode  isRange?: boolean}) {  return (    <div className="relative flex flex-col gap-4 md:flex-row">      <header className="absolute inset-x-0 top-0 flex w-full items-center justify-between gap-1">        <Button          variant={buttonVariant}          slot="previous"          className="size-(--cell-size) p-0 select-none aria-disabled:opacity-50"        >          <ChevronLeftIcon className="size-4" />        </Button>        <Button          variant={buttonVariant}          slot="next"          className="size-(--cell-size) p-0 select-none aria-disabled:opacity-50"        >          <ChevronRightIcon className="size-4" />        </Button>      </header>      {Array.from({ length: numberOfMonths }, (_, i) => (        <div key={i} className="flex w-full flex-col gap-4">          <div className="flex h-(--cell-size) w-full items-center justify-center gap-1 px-(--cell-size)">            {captionLayout === "dropdown" ? (              <>                <MonthDropdown format={headerFormat} />                <YearDropdown format={headerFormat} />              </>            ) : (              <CalendarHeading                offset={{ months: i }}                format={headerFormat}                className="text-sm font-medium select-none"              />            )}          </div>          <CalendarGrid            className="w-full border-collapse"            offset={{ months: i }}          >            <AriaCalendarGridHeader>              {(day) => (                <CalendarHeaderCell className="rounded-(--cell-radius) text-[0.8rem] font-normal text-muted-foreground select-none">                  {day}                </CalendarHeaderCell>              )}            </AriaCalendarGridHeader>            <CalendarGridBody>              {(date) => (                <CalendarCell                  date={date}                  className={(renderProps) =>                    cellVariants({ ...renderProps, showWeekNumber })                  }                >                  {(renderProps) => (                    <div                      data-selected-single={renderProps.isSelected && !isRange}                      data-range-start={renderProps.isSelectionStart && isRange}                      data-range-end={renderProps.isSelectionEnd && isRange}                      data-range-middle={                        renderProps.isSelected &&                        !renderProps.isSelectionStart &&                        !renderProps.isSelectionEnd &&                        isRange                      }                      className={cn(                        buttonVariants({ variant: "ghost", size: "icon" }),                        "relative isolate z-10 flex aspect-square h-full w-full min-w-(--cell-size) flex-col gap-1 border-0 leading-none font-normal group-data-[focused=true]/day:relative group-data-[focused=true]/day:z-10 group-data-[focused=true]/day:border-ring group-data-[focused=true]/day:ring-[3px] group-data-[focused=true]/day:ring-ring/50 data-[range-end=true]:rounded-(--cell-radius) data-[range-end=true]:rounded-r-(--cell-radius) data-[range-end=true]:bg-primary data-[range-end=true]:text-primary-foreground data-[range-middle=true]:rounded-none data-[range-middle=true]:bg-muted data-[range-middle=true]:text-foreground data-[range-start=true]:rounded-(--cell-radius) data-[range-start=true]:rounded-l-(--cell-radius) data-[range-start=true]:bg-primary data-[range-start=true]:text-primary-foreground data-[selected-single=true]:bg-primary data-[selected-single=true]:text-primary-foreground dark:hover:text-foreground [&>span]:text-xs [&>span]:opacity-70"                      )}                    >                      {renderCell                        ? renderCell(renderProps)                        : renderProps.defaultChildren}                    </div>                  )}                </CalendarCell>              )}            </CalendarGridBody>          </CalendarGrid>        </div>      ))}    </div>  )}
function MonthDropdown({ format }: { format?: Intl.DateTimeFormatOptions }) {  return (    <CalendarMonthPicker format={format?.month}>      {(props) => (        <Select {...props} className="relative">          <SelectTrigger>            <SelectValue />          </SelectTrigger>          <SelectContent className="min-w-0">            <SelectGroup>              {props.items.map((item) => (                <SelectItem key={item.id} id={item.id}>                  {item.formatted}                </SelectItem>              ))}            </SelectGroup>          </SelectContent>        </Select>      )}    </CalendarMonthPicker>  )}
function YearDropdown({ format }: { format?: Intl.DateTimeFormatOptions }) {  return (    <CalendarYearPicker format={format}>      {(props) => (        <Select {...props} className="relative">          <SelectTrigger>            <SelectValue />          </SelectTrigger>          <SelectContent className="min-w-0">            {props.items.map((item) => (              <SelectItem key={item.id} id={item.id}>                {item.formatted}              </SelectItem>            ))}          </SelectContent>        </Select>      )}    </CalendarYearPicker>  )}
export { Calendar, RangeCalendar }

Dates in React Aria are objects from @internationalized/date, which react-aria-components installs for you. If your code creates dates (CalendarDate, today, parseDate) or sets minValue, maxValue or defaultValue, import that package, and add it to your own dependencies so the import resolves:

pnpm add @internationalized/date

Usage

import { Calendar, RangeCalendar } from "@/components/ui/calendar"
<Calendar aria-label="Delivery date" className="rounded-lg border" />
import { CalendarDate } from "@internationalized/date"
<Calendar  aria-label="Delivery date"  defaultValue={new CalendarDate(2026, 12, 14)}  minValue={new CalendarDate(2026, 12, 1)}/>

The calendar has no border or radius of its own: add className="rounded-lg border" when it stands alone, and leave it bare inside a Popover or a Card, where it drops its background. The value is a date object, not a JavaScript Date. Call .toDate(timeZone) to get a Date, or .toString() for an ISO date such as 2026-12-14.

Give the calendar an aria-label that says what the date is for. It is read when focus enters the grid.

Examples

Controlled

value and onChange hold the selected date. onChange receives a date object. Format it for people with toDate("UTC") and timeZone: "UTC" so the displayed day never shifts with the time zone.

Delivery date, November 2026

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5

No delivery date chosen

Range

RangeCalendar selects a start and an end with two presses. Its value is an object with start and end. Use numberOfMonths to show two months side by side; they stack on narrow screens.

Production window, November to December 2026

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
29
30
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2

No production window chosen

Month and year dropdowns

captionLayout="dropdown" replaces the heading with a month and a year Select. Use it when the date can be far from today, such as a certificate issue date or a date of birth.

Audit date, November 2026

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5

Unavailable dates

isDateUnavailable receives each date and returns true when it cannot be chosen. Unavailable dates are struck through and skipped on selection, but stay in the grid so people can see why a day is missing. This example blocks Sundays.

Pickup date, November 2026

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5

Multiple dates

Set selectionMode="multiple" on Calendar to choose several separate days. The value is then an array of dates.

Controlled multiple selection

Passing an empty array as value to a calendar in multiple mode currently throws an error in this version of React Aria. Leave the calendar uncontrolled, or start with at least one date.

Inspection days, November 2026

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5

Disabled and read only

isDisabled greys out the grid and removes it from interaction. isReadOnly keeps the selection visible and focusable but does not let people change it. Prefer read only when people still need to read the date.

Delivery date, disabled, November 2026

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5

Delivery date, read only, November 2026

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5

Accessibility

KeyAction
ArrowLeftMoves focus to the previous day.
ArrowRightMoves focus to the next day.
ArrowUpMoves focus to the same day in the previous week.
ArrowDownMoves focus to the same day in the next week.
HomeMoves focus to the first day of the month.
EndMoves focus to the last day of the month.
PageUpMoves focus to the same day in the previous month.
PageDownMoves focus to the same day in the next month.
ShiftPageUpMoves focus to the same day in the previous year.
ShiftPageDownMoves focus to the same day in the next year.
EnterSelects the focused day.
SpaceSelects the focused day.
TabMoves focus between the previous and next buttons and the grid.

React Aria provides:

  • A grid of day cells with column headers, and a heading that announces the visible month when it changes.
  • Roving focus: one day is in the tab order, and arrow keys move within the grid, across month boundaries.
  • Localised month names, weekday labels and first day of the week, and right-to-left layout, from the current locale.
  • Selected, unavailable and disabled states exposed to assistive technology, and an announcement when the visible range changes.

You provide:

  • An aria-label on Calendar or RangeCalendar that names the date being chosen.
  • A visible text of the chosen date near the calendar, so the selection does not rely on the highlight alone.
  • A reason, near the calendar, when dates are unavailable.

Guidelines

When to use

  • To choose a date when people need to see the weekdays and their neighbours: a delivery date, a production window, a maintenance day.
  • To choose a range, such as the dates of a shutdown or a reporting period.
  • Inside a Date Picker, when the date goes in a form field.

When not to use

  • To fill a date field in a form where space is tight. Use a Date Picker, which keeps the calendar behind a button.
  • For a date that people know by heart, such as a date of birth, without the dropdowns. Use captionLayout="dropdown", or an input.
  • For a time, or a date with a time. Use a time input next to the picker.
  • To show events on a schedule. A calendar here only selects dates; it does not display appointments.

Content

  • Label with what the date means: "Delivery date", "Production window".
  • Show the chosen date in words ("14 December 2026") next to the calendar.
  • Explain unavailable dates in the text around it: "Deliveries are not made on Sundays."

Dates far from today

Certificate issue date, November 2026

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
Do

Add the month and year dropdowns when the date can be months or years away.

Certificate issue date, November 2026

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
Don’t

Don’t make people press the arrow dozens of times to reach a date far from today.

API reference

Calendar

Selects one date, or several with selectionMode="multiple". It renders the React Aria Calendar and accepts its props, except visibleDuration, which numberOfMonths sets.

PropTypeDefaultDescription
value?DateValue | nullNoneThe selected date, for a controlled calendar. An array with selectionMode multiple.
defaultValue?DateValue | nullNoneThe initial date of an uncontrolled calendar.
onChange?(value: DateValue) => voidNoneCalled when the selection changes.
selectionMode?"single" | "multiple""single"Whether one date or several can be chosen.
minValue?DateValueNoneThe earliest date that can be chosen.
maxValue?DateValueNoneThe latest date that can be chosen.
isDateUnavailable?(date: DateValue) => booleanNoneReturns true for dates that cannot be chosen.
isDisabled?booleanfalseDisables the whole calendar.
isReadOnly?booleanfalseShows the selection but does not let people change it.
isInvalid?booleanfalseMarks the selection as invalid.
focusedValue?DateValueNoneThe date that has focus, which also sets the visible month. Use with onFocusChange.
firstDayOfWeek?"sun" | "mon" | "tue" | "wed" | "thu" | "fri" | "sat"NoneThe day that starts the week. Defaults to the locale.
numberOfMonths?number1How many months are shown side by side.
captionLayout?"label" | "dropdown""label"A text heading, or month and year dropdowns.
showWeekNumber?booleanfalseOnly shifts the rounded corner of a selection to the second column. The calendar does not render week numbers yet.
headerFormat?Intl.DateTimeFormatOptionsNoneThe format of the month heading or the month dropdown.
buttonVariant?Button["variant"]"ghost"The button style of the previous and next buttons.
renderCell?(props) => ReactNodeNoneRenders the content of a day, with the default content passed in as defaultChildren.
aria-label?stringNoneThe accessible name of the calendar.
className?stringNoneClasses merged after the base classes. Set --cell-size here to change the size of the days.

RangeCalendar

Selects a range of dates. It renders the React Aria RangeCalendar and takes the same extra props as Calendar, apart from selectionMode.

PropTypeDefaultDescription
value?{ start: DateValue; end: DateValue } | nullNoneThe selected range, for a controlled calendar.
defaultValue?{ start: DateValue; end: DateValue } | nullNoneThe initial range of an uncontrolled calendar.
onChange?(value: { start: DateValue; end: DateValue }) => voidNoneCalled when a range is completed.
allowsNonContiguousRanges?booleanfalseLets a range span unavailable dates.