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-rc.0 |
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. |
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: 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. |
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. |
Example#
See the docs for useCalendar in react-aria for an example of useCalendarState
.