Date Range Picker
The Date Range Picker allows users to select a custom date range in the calendar. They can also navigate from one month to another. Date range pickers are especially helpful when a user needs to understand a date range in the context of other possible dates. For example, when there are limitations on the earliest possible start date (selections beyond that date would not be possible and dates would be faded out), or if only selections in the past can be made.
Unless used as the inline variant, the date range picker consists of two components: the trigger and the date range picker itself. Valid trigger components would be a Button or an Input. The trigger component should always reflect the currently selected date range, or a placeholder text (date format in case of an input, call to action label in case of button) if no selection has been made yet.
note
For a single date selection refer to the SingleDatePicker
Usage Rules
Do
- Use if the user wants to enter a date range
Don't
- Use if the user wants to enter a specific date. In this case, use the SingleDatePicker instead.
Example
Variants
Position of the current month
By default, the current month is displayed on the left
side but you can change this behavior by providing currentMonthPosition
prop.
Localization
The Date Range Picker has localization support. To make localization active, you can use the locale
prop.
info
Supported languages:
English (Default), Chinese, French, German, Japanese, Korean, Portuguese, Russian, Spanish, Turkish, Vietnamese
Highlighting a reference period
Highlight a reference period. Reference period date numbers will have a distinctive color. Note: This period won't be used in user's selection.
If set programmatically (by props), selected period and reference period can be outside of the maxDate
specified.
Custom Current Date
You can pass currentDate
. Its value will be assigned to "today".
Props
Name | Type | Default |
---|---|---|
onChange The handler will be called when both values of the date range are selected
and there is no onStateChange handler provided |
| — |
onStateChange The handler will be called if at least one date or focused input has been changed.
If provided onChange handler won't be called. |
| — |
startDate The beginning date of the selected date range. |
| null |
endDate The end date of the selected date range. |
| null |
referenceStartDate The beginning date of the reference date range to highlight. |
| null |
referenceEndDate The end date of the reference date range to highlight. |
| null |
minDate The earliest date the user can select |
| — |
maxDate The latest date the user can select |
| — |
currentDate The custom date to be used as the current date. If undefined, the machine current date is used. |
| — |
currentMonthPosition Use this prop to set the position of the current month |
| "left" |
isPeriodClicked Boolean prop for Period clicked on the DatepickerButton component |
| — |
handlePeriodClicked State handler to set PeriodClicked prop |
| — |
locale Use this prop to set localization for the date values |
| — |
dataTestIdNextSelection Next slection data-testid |
| — |
dataTestIdPrevSelection Previous slection data-testid |
| — |
css Add custom styles to this component. Use with caution. Learn more here: Link |
| — |
inputFieldCss |
| — |
data-{foo} Data attributes can be used by testing libraries to retrieve components or assert their existence |
| — |
* - the prop is required. |