Calendar
Shows a month grid so people can pick a date, several dates or a range of dates.
November 2026
| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
Installation
pnpm dlx shadcn@latest add @silkware/calendarTo copy the component by hand, install its dependencies:
pnpm add react-aria-components class-variance-authority cn lucide-reactThen copy the source into components/ui/calendar.tsx. It also needs Button and Select, used by the month and year dropdowns:
"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/dateUsage
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.
November 2026
| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
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.
November 2026
| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
December 2026
| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
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.
| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
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.
November 2026
| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
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.
November 2026
| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
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.
November 2026
| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
November 2026
| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
Accessibility
| Key | Action |
|---|---|
| ArrowLeft | Moves focus to the previous day. |
| ArrowRight | Moves focus to the next day. |
| ArrowUp | Moves focus to the same day in the previous week. |
| ArrowDown | Moves focus to the same day in the next week. |
| Home | Moves focus to the first day of the month. |
| End | Moves focus to the last day of the month. |
| PageUp | Moves focus to the same day in the previous month. |
| PageDown | Moves focus to the same day in the next month. |
| ShiftPageUp | Moves focus to the same day in the previous year. |
| ShiftPageDown | Moves focus to the same day in the next year. |
| Enter | Selects the focused day. |
| Space | Selects the focused day. |
| Tab | Moves focus between the previous and next buttons and the grid. |
React Aria provides:
- A
gridof 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-labelonCalendarorRangeCalendarthat 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
| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
Add the month and year dropdowns when the date can be months or years away.
November 2026
| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
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.
| Prop | Type | Default | Description |
|---|---|---|---|
value? | DateValue | null | None | The selected date, for a controlled calendar. An array with selectionMode multiple. |
defaultValue? | DateValue | null | None | The initial date of an uncontrolled calendar. |
onChange? | (value: DateValue) => void | None | Called when the selection changes. |
selectionMode? | "single" | "multiple" | "single" | Whether one date or several can be chosen. |
minValue? | DateValue | None | The earliest date that can be chosen. |
maxValue? | DateValue | None | The latest date that can be chosen. |
isDateUnavailable? | (date: DateValue) => boolean | None | Returns true for dates that cannot be chosen. |
isDisabled? | boolean | false | Disables the whole calendar. |
isReadOnly? | boolean | false | Shows the selection but does not let people change it. |
isInvalid? | boolean | false | Marks the selection as invalid. |
focusedValue? | DateValue | None | The date that has focus, which also sets the visible month. Use with onFocusChange. |
firstDayOfWeek? | "sun" | "mon" | "tue" | "wed" | "thu" | "fri" | "sat" | None | The day that starts the week. Defaults to the locale. |
numberOfMonths? | number | 1 | How many months are shown side by side. |
captionLayout? | "label" | "dropdown" | "label" | A text heading, or month and year dropdowns. |
showWeekNumber? | boolean | false | Only shifts the rounded corner of a selection to the second column. The calendar does not render week numbers yet. |
headerFormat? | Intl.DateTimeFormatOptions | None | The format of the month heading or the month dropdown. |
buttonVariant? | Button["variant"] | "ghost" | The button style of the previous and next buttons. |
renderCell? | (props) => ReactNode | None | Renders the content of a day, with the default content passed in as defaultChildren. |
aria-label? | string | None | The accessible name of the calendar. |
className? | string | None | Classes 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.
| Prop | Type | Default | Description |
|---|---|---|---|
value? | { start: DateValue; end: DateValue } | null | None | The selected range, for a controlled calendar. |
defaultValue? | { start: DateValue; end: DateValue } | null | None | The initial range of an uncontrolled calendar. |
onChange? | (value: { start: DateValue; end: DateValue }) => void | None | Called when a range is completed. |
allowsNonContiguousRanges? | boolean | false | Lets a range span unavailable dates. |