useCalendar

Provides the behavior and accessibility implementation for a calendar component. A calendar displays one or more date grids and allows users to select a single date.

July 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
31
Example
Calendar.tsx
Calendar.css
Button.tsx
Button.css
import {Calendar} from './Calendar';

<Calendar aria-label="Event date" />

API

September 2021SMTWTF5789101314151619202122232412326272930628S1118254CellGridNext button12176Previous button
<Calendar>
  <CalendarHeading />
  <CalendarMonthPicker />
  <CalendarYearPicker />
  <Button slot="previous" />
  <Button slot="next" />
  <CalendarGrid>
    <CalendarGridHeader>
      {day => <CalendarHeaderCell />}
    </CalendarGridHeader>
    <CalendarGridBody>
      {date => <CalendarCell date={date} />}
    </CalendarGridBody>
  </CalendarGrid>
  <Text slot="errorMessage" />
</Calendar>
useCalendarState<T extends = , M extends = 'single'>(props: <T, M>): <M>useCalendar<T extends , M extends = 'single'>(props: <T, M>, state: <M>): useCalendarGrid(props: , state: <>): useCalendarCell( props: , state: <>, ref: <HTMLElementnull> ): useCalendarMonthPicker(props: , state: <>): useCalendarYearPicker(props: , state: <>):

CalendarState

Properties

NameType
value<null, >

The currently selected date.

isDisabledboolean

Whether the calendar is disabled.

isReadOnlyboolean

Whether the calendar is in a read only state.

visibleDuration

The visible duration in the calendar.

visibleRange<>

The date range that is currently visible in the calendar.

timeZonestring

The time zone of the dates currently being displayed.

isValueInvalidboolean

Whether the calendar is invalid.

focusedDate

The currently focused date.

isFocusedboolean

Whether focus is currently within the calendar.

selectionMode

Whether single or multiple selection is enabled.

Methods

setValue(value: <null, >): void
Sets the currently selected date.
setFocusedDate(value: ): void
Sets the focused date.
focusNextDay(): void
Moves focus to the next calendar date.
focusPreviousDay(): void
Moves focus to the previous calendar date.
focusNextRow(): void
Moves focus to the next row of dates, e.g. the next week.
focusPreviousRow(): void
Moves focus to the previous row of dates, e.g. the previous work.
focusNextPage(): void
Moves focus to the next page of dates, e.g. the next month if one month is visible.
focusPreviousPage(): void
Moves focus to the previous page of dates, e.g. the previous month if one month is visible.
focusSectionStart(): void
Moves focus to the start of the current section of dates, e.g. the start of the current month.
focusSectionEnd(): void
Moves focus to the end of the current section of dates, e.g. the end of the current month month.
focusNextSection(larger?: boolean): void
Moves focus to the next section of dates based on what is currently displayed. By default, focus is moved by one of the currently displayed unit. For example, if one or more months are displayed, then focus is moved forward by one month. If the larger option is true, the focus is moved by the next larger unit than the one displayed. For example, if months are displayed, then focus moves to the next year.
focusPreviousSection(larger?: boolean): void
Moves focus to the previous section of dates based on what is currently displayed. By default, focus is moved by one of the currently displayed unit. For example, if one or more months are displayed, then focus is moved backward by one month. If the larger option is true, the focus is moved by the next larger unit than the one displayed. For example, if months are displayed, then focus moves to the previous year.
selectFocusedDate(): void
Selects the currently focused date.
selectDate(date: ): void
Selects the given date.
setFocused(value: boolean): void
Sets whether focus is currently within the calendar.
isInvalid(date: ): boolean
Returns whether the given date is invalid according to the minValue and maxValue props.
isSelected(date: ): boolean
Returns whether the given date is currently selected.
isCellFocused(date: ): boolean
Returns whether the given date is currently focused.
isCellDisabled(date: ): boolean
Returns whether the given date is disabled according to the minValue,maxValue, andisDisabled` props.
isCellUnavailable(date: ): boolean
Returns whether the given date is unavailable according to the isDateUnavailable prop.
isPreviousVisibleRangeInvalid(): boolean
Returns whether the previous visible date range is allowed to be selected according to the minValue prop.
isNextVisibleRangeInvalid(): boolean
Returns whether the next visible date range is allowed to be selected according to the maxValue prop.
getDatesInWeek(weekIndex: number, startDate?: ): Array<null>
Returns an array of dates in the week index counted from the provided start date, or the first visible date if not given. The returned array always has 7 elements, but may include null if the date does not exist according to the calendar system.
getWeeksInMonth(startDate?: ): number
Returns the number of weeks in a month.

AriaCalendarProps

NameTypeDefault
isDateUnavailable(date: ) => booleanDefault:

Callback that is called for each date of the calendar. If it returns true, then the date is unavailable.

isDisabledbooleanDefault: false

Whether the calendar is disabled.

isReadOnlybooleanDefault: false

Whether the calendar value is immutable.

focusedValuenullDefault:

Controls the currently focused date within the calendar.

defaultFocusedValuenullDefault:

The date that is focused when the calendar first mounts (uncontrolled).

pageBehaviorDefault: visible

Controls the behavior of paging. Pagination either works by advancing the visible page by visibleDuration (default) or one unit of visibleDuration.

firstDayOfWeek'sun''mon''tue''wed''thu''fri''sat'Default:

The day that starts the week.

selectionAlignment'start''center''end'Default: 'center'

Determines the alignment of the visible months on initial render based on the current selection or current date if there is no selection.

weeksInMonthnumberDefault:

The number of weeks in a month. This overrides the default set by the locale.

selectionModeDefault: 'single'

Whether single or multiple selection is enabled.

value<null, >Default:

The current value (controlled).

defaultValue<null, >Default:

The default value (uncontrolled).

onChange(value: <<>, >) => voidDefault:

Handler that is called when the value changes.

CalendarAria

NameType
calendarPropsDOMAttributes

Props for the calendar grouping element.

nextButtonProps

Props for the next button.

prevButtonProps

Props for the previous button.

errorMessagePropsDOMAttributes

Props for the error message element, if any.

titlestring

A description of the visible date range, for use in the calendar title.

AriaCalendarGridProps

NameTypeDefault
startDateDefault:

The first date displayed in the calendar grid. Defaults to the first visible date in the calendar. Override this to display multiple date grids in a calendar.

endDateDefault:

The last date displayed in the calendar grid. Defaults to the last visible date in the calendar. Override this to display multiple date grids in a calendar.

weekdayStyle'narrow''short''long'Default: 'narrow'

The style of weekday names to display in the calendar grid header, e.g. single letter, abbreviation, or full day name.

firstDayOfWeek'sun''mon''tue''wed''thu''fri''sat'Default:

The day that starts the week.

CalendarGridAria

NameType
gridPropsDOMAttributes

Props for the date grid element (e.g. <table>).

headerPropsDOMAttributes

Props for the grid header element (e.g. <thead>).

weekDaysstring[]

A list of week day abbreviations formatted for the current locale, typically used in column headers.

weeksInMonthnumber

The number of weeks in the month.

AriaCalendarCellProps

NameType
date

The date that this cell represents.

isDisabledboolean

Whether the cell is disabled. By default, this is determined by the Calendar's minValue, maxValue, and isDisabled props.

isOutsideMonthboolean

Whether the cell is outside of the current month.

CalendarCellAria

NameType
cellPropsDOMAttributes

Props for the grid cell element (e.g. <td>).

buttonPropsDOMAttributes

Props for the button element within the cell.

isPressedboolean

Whether the cell is currently being pressed.

isSelectedboolean

Whether the cell is selected.

isFocusedboolean

Whether the cell is focused.

isDisabledboolean

Whether the cell is disabled, according to the calendar's minValue, maxValue, and isDisabled props. Disabled dates are not focusable, and cannot be selected by the user. They are typically displayed with a dimmed appearance.

isUnavailableboolean

Whether the cell is unavailable, according to the calendar's isDateUnavailable prop. Unavailable dates remain focusable, but cannot be selected by the user. They should be displayed with a visual affordance to indicate they are unavailable, such as a different color or a strikethrough.

Note that because they are focusable, unavailable dates must meet a 4.5:1 color contrast ratio, as defined by WCAG.

isOutsideVisibleRangeboolean

Whether the cell is outside the visible range of the calendar. For example, dates before the first day of a month in the same week.

formattedDatestring

The day number formatted according to the current locale.

CalendarMonthPickerProps

NameType
format'numeric''2-digit''long''short''narrow'

The format of the month.

CalendarMonthPickerAria

NameType
valueKey
items[]
onChange(key: Keynull) => void

CalendarYearPickerProps

NameTypeDefault
visibleYearsnumberDefault: 20

The number of years to display.

formatDefault:

The format to display.

CalendarYearPickerAria

NameType
valueKey
items[]
onChange(key: Keynull) => void