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.27.0 |
usage | import {useDateRangePickerState} from 'react-stately' |
API#
useDateRangePickerState<T extends DateValue = DateValue>(
(props: DateRangePickerStateOptions<T>
)): DateRangePickerState
Interface#
Properties
Name | Type | Description |
value | DateRange | null | The currently selected date range. |
dateRange | DateRange | null | The date portion of the selected range. This may be set prior to |
timeRange | TimeRange | null | 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. |
isInvalid | boolean | Whether the date range picker is invalid, based on the isInvalid , minValue , and maxValue props. |
Methods
Method | Description |
setValue(
(value: DateRange
| | null
)): 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
.