useRangeCalendarState
Provides state management for a range calendar component. A range calendar displays one or more date grids and allows users to select a contiguous range of dates.
install | yarn add react-stately |
---|---|
version | 3.21.0 |
usage | import {useRangeCalendarState} from 'react-stately' |
API#
useRangeCalendarState<T extends DateValue = DateValue>(
(props: RangeCalendarStateOptions<T>
)): RangeCalendarState
Interface#
Properties
Name | Type | Description |
value | RangeValue<DateValue> | The currently selected date range. |
anchorDate | CalendarDate | null | The current anchor date that the user clicked on to begin range selection. |
highlightedRange | RangeValue<CalendarDate> | The currently highlighted date range. |
isDragging | boolean | Whether the user is currently dragging over the calendar. |
isDisabled | boolean | Whether the calendar is disabled. |
isReadOnly | boolean | Whether the calendar is in a read only state. |
visibleRange | RangeValue<CalendarDate> | The date range that is currently visible in the calendar. |
timeZone | string | The time zone of the dates currently being displayed. |
validationState | ValidationState | The current validation state of the selected value. |
focusedDate | CalendarDate | The currently focused date. |
isFocused | boolean | Whether focus is currently within the calendar. |
minValue | DateValue | The minimum allowed date that a user may select. |
maxValue | DateValue | The maximum allowed date that a user may select. |
Methods
Method | Description |
setValue(
(value: RangeValue<DateValue>
)): void | Sets the currently selected date range. |
highlightDate(
(date: CalendarDate
)): void | Highlights the given date during selection, e.g. by hovering or dragging. |
setAnchorDate(
(date: CalendarDate
| | 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. |
setFocusedDate(
(value: CalendarDate
)): 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 |
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 |
selectFocusedDate(): void | Selects the currently focused date. |
selectDate(
(date: CalendarDate
)): void | Selects the given date. |
setFocused(
(value: boolean
)): void | Sets whether focus is currently within the calendar. |
isInvalid(
(date: CalendarDate
)): boolean | Returns whether the given date is invalid according to the minValue and maxValue props. |
isSelected(
(date: CalendarDate
)): boolean | Returns whether the given date is currently selected. |
isCellFocused(
(date: CalendarDate
)): boolean | Returns whether the given date is currently focused. |
isCellDisabled(
(date: CalendarDate
)): boolean | Returns whether the given date is disabled according to the minValue, maxValue, and isDisabled` props. |
isCellUnavailable(
(date: CalendarDate
)): 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?: CalendarDate
)): Array<CalendarDate | 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. |
Example#
See the docs for useRangeCalendar in react-aria for an example of useRangeCalendarState
.