useDateRangePickerState
Provides state management for a date range picker component. A date range picker combines two DateFields and a RangeCalendar popover to allow users to enter or select a date and time range.
install | yarn add react-stately |
---|---|
version | 3.21.0 |
usage | import {useDateRangePickerState} from 'react-stately' |
API#
useDateRangePickerState<T extends DateValue = DateValue>(
(props: DateRangePickerStateOptions<T>
)): DateRangePickerState
Interface#
Properties
Name | Type | Description |
value | DateRange | The currently selected date range. |
dateRange | DateRange | The date portion of the selected range. This may be set prior to |
timeRange | TimeRange | The time portion of the selected range. This may be set prior to |
granularity | Granularity | The granularity for the field, based on the granularity prop and current value. |
hasTime | boolean | Whether the date range picker supports selecting times, according to the granularity prop and current value. |
isOpen | boolean | Whether the calendar popover is currently open. |
validationState | ValidationState | The current validation state of the date picker, based on the validationState , minValue , and maxValue props. |
Methods
Method | Description |
setValue(
(value: DateRange
)): void | Sets the selected date range. |
setDateRange(
(value: DateRange
)): void | Sets the date portion of the selected range. |
setTimeRange(
(value: TimeRange
)): void | Sets the time portion of the selected range. |
setDate(
(part: 'start'
| | 'end',
, value: DateValue
)): void | Sets the date portion of either the start or end of the selected range. |
setTime(
(part: 'start'
| | 'end',
, value: TimeValue
)): void | Sets the time portion of either the start or end of the selected range. |
setDateTime(
(part: 'start'
| | 'end',
, value: DateValue
)): void | Sets the date and time of either the start or end of the selected range. |
setOpen(
(isOpen: boolean
)): void | Sets whether the calendar popover is open. |
formatValue(
(locale: string,
, fieldOptions: FieldOptions
)): {} | Formats the selected range using the given options. |
open(): void | Opens the overlay. |
close(): void | Closes the overlay. |
toggle(): void | Toggles the overlay's visibility. |
Example#
See the docs for useDateRangePicker in react-aria for an example of useDateRangePickerState
.