useDateRangePicker

Provides the behavior and accessibility implementation for a date 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.

Trip dates
Example
DateRangePicker.tsx
DateRangePicker.css
DateField.css
RangeCalendar.css
Button.css
Form.css
Popover.css
import {DateRangePicker} from './DateRangePicker';

<DateRangePicker label="Trip dates" />

API

September 2021SMTWTF5789101314151619202122232412326272930628S111825412176Event dateGroupLabelButtonStart fieldEnd fieldRangeCalendarPopover9 / 17 / 20219 / 6 / 2021 –
<DateRangePicker>
  <Label />
  <Group>
    <DateInput slot="start">
      {segment => <DateSegment segment={segment} />}
    </DateInput>
    <span aria-hidden="true">–</span>
    <DateInput slot="end">
      {segment => <DateSegment segment={segment} />}
    </DateInput>
    <Button />
  </Group>
  <Popover>
    <RangeCalendar />
  </Popover>
</DateRangePicker>
useDateRangePickerState<T extends = >(props: <T>): useDateRangePicker<T extends >( props: <T>, state: , ref: <Elementnull> ):

DateRangePickerState

Properties

NameType
dateRange<null>null

The date portion of the selected range. This may be set prior to value if the user has selected a date range but has not yet selected a time range.

timeRange<null>null

The time portion of the selected range. This may be set prior to value if the user has selected a time range but has not yet selected a date range.

granularity

The granularity for the field, based on the granularity prop and current value.

hasTimeboolean

Whether the date range picker supports selecting times, according to the granularity prop and current value.

pointnull

The cursor position when the overlay was triggered, relative to the window viewport.

realtimeValidation

Realtime validation results, updated as the user edits the value.

displayValidation

Currently displayed validation results, updated when the user commits their changes.

value<null>

The currently selected date range.

defaultValuenull

The default selected date range.

Methods

setValue(value: null): void
Sets the selected date range.
setDateRange(value: ): void
Sets the date portion of the selected range.
setTimeRange(value: ): void
Sets the time portion of the selected range.
setDate(part: 'start''end', value: null): void
Sets the date portion of either the start or end of the selected range.
setTime(part: 'start''end', value: null): void
Sets the time portion of either the start or end of the selected range.
setDateTime(part: 'start''end', value: 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: ): {
start: string,
end: string
}null
Formats the selected range using the given options.
getDateFormatter(locale: string, formatOptions: ):
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.
setPoint(point: ): void
Sets the cursor position relative to the window viewport.
updateValidation(result: ): 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.

AriaDateRangePickerProps

NameTypeDefault
allowsNonContiguousRangesbooleanDefault:

When combined with isDateUnavailable, determines whether non-contiguous ranges, i.e. ranges containing unavailable dates, may be selected.

isDateUnavailable(date: , anchorDate: null) => booleanDefault:

Callback that is called for each date of the calendar. If it returns true, then the date is unavailable.

pageBehaviorDefault: visible

Controls the behavior of paging. Pagination either works by advancing the visible page by visibleDuration (default) or one unit of visibleDuration.

firstDayOfWeek'sun''mon''tue''wed''thu''fri''sat'Default:

The day that starts the week.

placeholderValuenullDefault:

A placeholder date that influences the format of the placeholder shown when no value is selected. Defaults to today's date at midnight.

hourCycle1224Default:

Whether to display the time in 12 or 24 hour format. By default, this is determined by the user's locale.

granularityDefault:

Determines the smallest unit that is displayed in the date picker. By default, this is "day" for dates, and "minute" for times.

hideTimeZonebooleanDefault: false

Whether to hide the time zone abbreviation.

shouldForceLeadingZerosbooleanDefault:

Whether to always show leading zeros in the month, day, and hour fields. By default, this is determined by the user's locale.

isDisabledbooleanDefault:

Whether the input is disabled.

isReadOnlybooleanDefault:

Whether the input can be selected but not changed by the user.

value<>nullDefault:

The current value (controlled).

defaultValue<>nullDefault:

The default value (uncontrolled).

onChange(value: <<>>null) => voidDefault:

Handler that is called when the value changes.

DateRangePickerAria

NameType
labelPropsDOMAttributes

Props for the date range picker's visible label element, if any.

groupProps

Props for the grouping element containing the date fields and button.

startFieldProps<>

Props for the start date field.

endFieldProps<>

Props for the end date field.

buttonProps

Props for the popover trigger button.

descriptionPropsDOMAttributes

Props for the description element, if any.

errorMessagePropsDOMAttributes

Props for the error message element, if any.

dialogProps

Props for the popover dialog.

calendarProps<>

Props for the range calendar within the popover dialog.

validationDetailsValidityState

The native validation details for the input.