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/calendar |
---|---|
version | 3.0.0-alpha.4 |
usage | import {useRangeCalendarState} from '@react-stately/calendar' |
API#
useRangeCalendarState(
(props: RangeCalendarStateOptions
)): 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. |
focusedDate | CalendarDate | The currently focused date. |
isFocused | boolean | Whether focus is currently within the calendar. |
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. |
focusPageStart(): void | Moves focus to the start of the current page of dates, e.g. the start of the first visible month. |
focusPageEnd(): void | Moves focus to the end of the current page of dates, e.g. the end of the last visible month. |
focusNextSection(): void | Moves focus to the next larger section of dates based on what is currently displayed. If days are displayed, then moves to the next visible range. If weeks are displayed, then moves to the next month. If months or years are displayed, moves to the next year. |
focusPreviousSection(): void | Moves focus to the previous larger section of dates based on what is currently displayed. If days are displayed, then moves to the previous visible range. If weeks are displayed, then moves to the previous month. If months or years are displayed, moves to the previous year. |
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. |
Example#
See the docs for useRangeCalendar in react-aria for an example of useRangeCalendarState
.