A date range picker combines two DateFields and a RangeCalendar popover to allow users to enter or select a date and time range.
There is not much change in this component as compared to react-aria-components's export. You can refer to the official documentation for more details.
You can add a description to the DateRangePicker by passing the description property.
You can combine the isInvalid and errorMessage properties to show an invalid input.
If the value (or defaultValue) given to DateRangePicker includes time information, time fields will be shown in the DateFields.
You can use the value and onChange properties to control the input value.
Selected date range: 1 July 2024 to 8 July 2024
DateRangePicker is timezone aware when a ZonedDateTime object is provided as the value. In this case, the time zone abbreviation is displayed,
and time zone concerns such as daylight saving time are taken into account when the value is manipulated.
@internationalized/date includes functions for parsing strings in multiple formats into ZonedDateTime objects.
pnpm add @internationalized/date
import { parseZonedDateTime } from "@internationalized/date"The granularity prop allows you to control the smallest unit that is displayed by DateRangePicker. By default, the value is displayed with "day" granularity (year, month, and day),
and CalendarDateTime and ZonedDateTime values are displayed with "minute" granularity.
@internationalized/date includes functions for parsing strings in multiple formats into ZonedDateTime objects.
pnpm add @internationalized/date
import { DateValue, parseAbsoluteToLocal } from "@internationalized/date"
import { useDateFormatter } from "@react-aria/i18n"Selected date range: 7/4/21, 6:45:22 pm UTC to 8/4/21, 8:00:00 pm UTC
The minValue and maxValue props can also be used to ensure the value is within a specific range.
You may also want to use RangeCalendar's isDateUnavailable (via calendarProps) prop to visually indicate which dates are unavailable for selection in the calendar.
@internationalized/date includes functions for parsing strings in multiple formats into ZonedDateTime objects.
pnpm add @internationalized/date
import { getLocalTimeZone, parseDate, today } from "@internationalized/date"DateRangePicker supports selecting dates in many calendar systems used around the world,
including Gregorian, Hebrew, Indian, Islamic, Buddhist, and more.
Dates are automatically displayed in the appropriate calendar system for the user's locale.
The calendar system can be overridden using the https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/calendar#adding_a_calendar_in_the_locale_string,
passed to the I18nProvider component.
@internationalized/date includes functions for parsing strings in multiple formats into ZonedDateTime objects.
pnpm add @internationalized/date
import { parseAbsoluteToLocal } from "@internationalized/date"
import { I18nProvider } from "@react-aria/i18n"DateRangePicker supports marking certain dates as unavailable. These dates cannot be selected by the user and are displayed with a crossed out appearance in the calendar. In the date field, an invalid state is displayed if a user enters an unavailable date.
@internationalized/date includes functions for parsing strings in multiple formats into ZonedDateTime objects.
pnpm add @internationalized/date
import { getLocalTimeZone, isWeekend, today } from "@internationalized/date"
import { useLocale } from "@react-aria/i18n"By default, the calendar popover displays two months.
You can use the calendarProps#visibleDuration to pass a custom duration to display more months at once.
By default, the first day of the week is determined by the user's locale. You can override this using the calendarProps#firstDayOfWeek prop.
The available values are 'sun', 'mon', 'tue', 'wed', 'thu', 'fri', and 'sat'.
By default, when pressing the next or previous buttons, pagination will advance by a single month.
This behavior can be changed to page by the visible months instead, by setting calendarProps#pageBehavior to "visible".
You can also override styles of the various components used within DateRangePicker:
Slots can be overridden via the classNames.calendar prop or calendarProps#classNames prop.
Slots can be overridden via the classNames.popover prop or popoverProps#classNames prop.
Slots can be overridden via the classNames.error prop.