useDatePickerState
Provides state management for a date picker component. A date picker combines a DateField and a Calendar popover to allow users to enter or select a date and time value.
install | yarn add @react-stately/datepicker |
---|---|
version | 3.0.0-alpha.4 |
usage | import {useDatePickerState} from '@react-stately/datepicker' |
API#
useDatePickerState(
(props: DatePickerOptions
)): DatePickerState
Interface#
Properties
Name | Type | Description |
value | DateValue | The currently selected date. |
dateValue | DateValue | The date portion of the value. This may be set prior to |
timeValue | TimeValue | The time portion of the value. 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 picker supports selecting a time, 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: DateValue
)): void | Sets the selected date. |
setDateValue(
(value: CalendarDate
)): void | Sets the date portion of the value. |
setTimeValue(
(value: TimeValue
)): void | Sets the time portion of the value. |
setOpen(
(isOpen: boolean
)): void | Sets whether the calendar popover is open. |
formatValue(
(locale: string,
, fieldOptions: FieldOptions
)): string | Formats the selected value using the given options. |
Example#
See the docs for useDatePicker in react-aria for an example of useDatePickerState
.