alpha

useCalendarState

Provides state management for a calendar component. A calendar displays one or more date grids and allows users to select a single date.

installyarn add @react-stately/calendar
version3.0.0-alpha.4
usageimport {useCalendarState} from '@react-stately/calendar'

API#


useCalendarState( (props: CalendarStateOptions )): CalendarState

Interface#


Properties

NameTypeDescription
valueCalendarDateThe currently selected date.
isDisabledbooleanWhether the calendar is disabled.
isReadOnlybooleanWhether the calendar is in a read only state.
visibleRangeRangeValue<CalendarDate>The date range that is currently visible in the calendar.
timeZonestringThe time zone of the dates currently being displayed.
focusedDateCalendarDateThe currently focused date.
isFocusedbooleanWhether focus is currently within the calendar.

Methods

MethodDescription
setValue( (value: CalendarDate )): voidSets the currently selected date.
setFocusedDate( (value: CalendarDate )): voidSets the focused date.
focusNextDay(): voidMoves focus to the next calendar date.
focusPreviousDay(): voidMoves focus to the previous calendar date.
focusNextRow(): voidMoves focus to the next row of dates, e.g. the next week.
focusPreviousRow(): voidMoves focus to the previous row of dates, e.g. the previous work.
focusNextPage(): voidMoves focus to the next page of dates, e.g. the next month if one month is visible.
focusPreviousPage(): voidMoves focus to the previous page of dates, e.g. the previous month if one month is visible.
focusPageStart(): voidMoves focus to the start of the current page of dates, e.g. the start of the first visible month.
focusPageEnd(): voidMoves 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(): voidSelects the currently focused date.
selectDate( (date: CalendarDate )): voidSelects the given date.
setFocused( (value: boolean )): voidSets whether focus is currently within the calendar.
isInvalid( (date: CalendarDate )): booleanReturns whether the given date is invalid according to the minValue and maxValue props.
isSelected( (date: CalendarDate )): booleanReturns whether the given date is currently selected.
isCellFocused( (date: CalendarDate )): booleanReturns whether the given date is currently focused.
isCellDisabled( (date: CalendarDate )): booleanReturns whether the given date is disabled according to the minValue,maxValue, andisDisabled` props.
isCellUnavailable( (date: CalendarDate )): booleanReturns whether the given date is unavailable according to the isDateUnavailable prop.
isPreviousVisibleRangeInvalid(): booleanReturns whether the previous visible date range is allowed to be selected according to the minValue prop.
isNextVisibleRangeInvalid(): booleanReturns 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.