useRangeCalendar

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

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
RangeCalendar.tsx
RangeCalendar.css
Button.tsx
Button.css
import {RangeCalendar} from './RangeCalendar';

<RangeCalendar aria-label="Trip dates" />

API

September 2021SMTWTF5789101314151619202122232412326272930628S111825412176CellGridNext buttonPrevious button
<RangeCalendar>
  <CalendarHeading />
  <CalendarMonthPicker />
  <CalendarYearPicker />
  <Button slot="previous" />
  <Button slot="next" />
  <CalendarGrid>
    <CalendarGridHeader>
      {day => <CalendarHeaderCell />}
    </CalendarGridHeader>
    <CalendarGridBody>
      {date => <CalendarCell date={date} />}
    </CalendarGridBody>
  </CalendarGrid>
  <Text slot="errorMessage" />
</RangeCalendar>
useRangeCalendarState<T extends = >(props: <T>): <T>useRangeCalendar<T extends >( props: <T>, state: , ref: <FocusableElementnull> ): useCalendarGrid(props: , state: <>): useCalendarCell( props: , state: <>, ref: <HTMLElementnull> ): useCalendarMonthPicker(props: , state: <>): useCalendarYearPicker(props: , state: <>):

RangeCalendarState

Properties

NameType
value<>null

The currently selected date range.

anchorDatenull

The current anchor date that the user clicked on to begin range selection.

highlightedRange<>null

The currently highlighted date range.

isDraggingboolean

Whether the user is currently dragging over the calendar.

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.

Methods

setValue(value: <>null): void
Sets the currently selected date range.
highlightDate(date: ): void
Highlights the given date during selection, e.g. by hovering or dragging.
setAnchorDate(date: null): void
Sets the anchor date that the user clicked on to begin range selection.
setDragging(isDragging: boolean): void
Sets whether the user is dragging over the calendar.
clearSelection(): void
Clears the current selection.
commitSelection(): void
Commits the current selection.
focusNearestAvailableDate(anchorDate: ): void
Focuses the next available day before or after the anchor 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.

AriaRangeCalendarProps

NameTypeDefault
commitBehavior'clear''reset''select'Default: 'select'

Controls the behavior when a pointer is released outside the calendar or a blur occurs mid selection:

  • clear: clear the currently selected range of dates.
  • reset: reset the selection to the previously selected range of dates.
  • select: select the currently hovered range of dates.
allowsNonContiguousRangesbooleanDefault:

When combined with isDateUnavailable, determines whether non-contiguous ranges, i.e. ranges containing unavailable dates, may be selected.

isDateUnavailable(date: , anchorDate: null) => booleanDefault:

Callback that is called for each date of the calendar. If it returns true, then the date is unavailable. The second argument provides the current selection anchor date, if any. This can be used to adjust the available dates based on the user's first selected date.

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.

value<>nullDefault:

The current value (controlled).

defaultValue<>nullDefault:

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.

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.

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