DateRangePicker
DateRangePickers combine two DateFields and a RangeCalendar popover to allow users to enter or select a date and time range.
firstDayOfWeek
Value
Use the value
or defaultValue
prop to set the selected date range, using objects in the @internationalized/date package. This library supports parsing date strings in multiple formats, manipulation across international calendar systems, time zones, etc.
Selected range: February 3 – 12, 2025
import {parseDate, getLocalTimeZone} from '@internationalized/date';
import {useDateFormatter} from 'react-aria';
import {DateRangePicker} from '@react-spectrum/s2';
import {useState} from 'react';
function Example() {
let [range, setRange] = useState({
start: parseDate('2025-02-03'),
end: parseDate('2025-02-12')
});
let formatter = useDateFormatter({ dateStyle: 'long' });
return (
<>
<DateRangePicker
value={range}
onChange={setRange} />
<p>Selected range: {formatter.formatRange(
range.start.toDate(getLocalTimeZone()),
range.end.toDate(getLocalTimeZone())
)}</p>
</>
);
}
Format options
The date format is automatically determined based on the user's locale. DateRangePicker
supports several props to control how values are displayed.
granularity
"day"
for dates, and "minute"
for times.International calendars
By default, DateRangePicker
displays the value using the calendar system for the user's locale. Use <Provider>
to override the calendar system by setting the Unicode calendar locale extension. The onChange
event always receives a date in the same calendar as the value
or defaultValue
(Gregorian if no value is provided), regardless of the displayed locale.
Forms
Use the name
prop to submit the selected date to the server as an ISO 8601 string. Set the isRequired
, minValue
, or maxValue
props to validate the value, or implement custom client or server-side validation. The isDateUnavailable
callback prevents certain dates from being selected. Use allowsNonContiguousRanges
to allow selecting ranges containing unavailable dates. See the Forms guide to learn more.
API
Name | Type | Default |
---|---|---|
size | 'S'
| 'M'
| 'L'
| 'XL' | Default: 'M'
|
The size of the DateField. | ||
maxVisibleMonths | number | Default: 1
|
The maximum number of months to display at once in the calendar popover, if screen space permits. | ||
pageBehavior | PageBehavior | Default: 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. | ||
isDateUnavailable |
| Default: — |
Callback that is called for each date of the calendar. If it returns true, then the date is unavailable. | ||
placeholderValue | DateValue | null | Default: — |
A placeholder date that influences the format of the placeholder shown when no value is selected. Defaults to today's date at midnight. | ||
hourCycle | 12 | 24 | Default: — |
Whether to display the time in 12 or 24 hour format. By default, this is determined by the user's locale. | ||
granularity | Granularity | Default: — |
Determines the smallest unit that is displayed in the date picker. By default, this is "day" for dates, and "minute" for times. | ||
hideTimeZone | boolean | Default: false
|
Whether to hide the time zone abbreviation. | ||
shouldForceLeadingZeros | boolean | Default: — |
Whether to always show leading zeros in the month, day, and hour fields. By default, this is determined by the user's locale. | ||
isDisabled | boolean | Default: — |
Whether the input is disabled. | ||
isReadOnly | boolean | Default: — |
Whether the input can be selected but not changed by the user. | ||
allowsNonContiguousRanges | boolean | Default: — |
When combined with isDateUnavailable , determines whether non-contiguous ranges,
i.e. ranges containing unavailable dates, may be selected. | ||
styles | StylesProp | Default: — |
Spectrum-defined styles, returned by the style() macro. | ||
value | RangeValue | Default: — |
The current value (controlled). | ||
defaultValue | RangeValue | Default: — |
The default value (uncontrolled). | ||
onChange |
| Default: — |
Handler that is called when the value changes. | ||