useCalendarState
Provides state management for a calendar component. A calendar displays one or more date grids and allows users to select a single date.
install | yarn add @react-stately/calendar |
---|---|
version | 3.0.0-alpha.4 |
usage | import {useCalendarState} from '@react-stately/calendar' |
API#
useCalendarState(
(props: CalendarStateOptions
)): CalendarState
Interface#
Properties
Name | Type | Description |
value | CalendarDate | The currently selected date. |
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: CalendarDate
)): void | Sets the currently selected date. |
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 useCalendar in react-aria for an example of useCalendarState
.