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.33.1 |
usage | import {useDateRangePickerState} from 'react-stately' |
API#
useDateRangePickerState<T extends DateValue = DateValue>(
(props: DateRangePickerStateOptions<T>
)): DateRangePickerState
Interface#
Properties
Name | Type | Description |
value | RangeValue<DateValue | null> | The currently selected date range. |
dateRange | RangeValue<DateValue | null> | null | The date portion of the selected range. This may be set prior to |
timeRange | RangeValue<TimeValue | null> | 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. |
realtimeValidation | ValidationResult | Realtime validation results, updated as the user edits the value. |
displayValidation | ValidationResult | Currently displayed validation results, updated when the user commits their changes. |
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
| | null
)): void | Sets the date portion of either the start or end of the selected range. |
setTime(
(part: 'start'
| | 'end',
, value: TimeValue
| | null
)): void | Sets the time portion of either the start or end of the selected range. |
setDateTime(
(part: 'start'
| | 'end',
, value: DateValue
| | null
)): 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
)): {} | null | Formats the selected range using the given options. |
getDateFormatter(
(locale: string,
, formatOptions: FormatterOptions
)): DateFormatter | Gets a formatter based on state's props. |
open(): void | Opens the overlay. |
close(): void | Closes the overlay. |
toggle(): void | Toggles the overlay's visibility. |
updateValidation(
(result: ValidationResult
)): void | Updates the current validation result. Not displayed to the user until commitValidation is called. |
resetValidation(): void | Resets the displayed validation state to valid when the user resets the form. |
commitValidation(): void | Commits the realtime validation so it is displayed to the user. |
Example#
See the docs for useDateRangePicker in react-aria for an example of useDateRangePickerState
.