Date Range Picker
Features
- Full keyboard navigation
- Can be controlled or uncontrolled
- Focus is fully managed
- Localization support
- Accessible by default
- Supports both date and date-time formats
Preface
The component depends on the @internationalized/date package, which solves a lot of the problems that come with working with dates and times in JavaScript.
We highly recommend reading through the documentation for the package to get a solid feel for how it works, and you'll need to install it in your project to use the date-related components.
Installation
Install the date package.
$ npm add @internationalized/dateInstall the component from your command line.
$ npm add reka-uiAnatomy
Import all parts and piece them together.
<script setup>
import {
DateRangePickerAnchor,
DateRangePickerArrow,
DateRangePickerCalendar,
DateRangePickerCell,
DateRangePickerCellTrigger,
DateRangePickerClose,
DateRangePickerContent,
DateRangePickerField,
DateRangePickerGrid,
DateRangePickerGridBody,
DateRangePickerGridHead,
DateRangePickerGridRow,
DateRangePickerHeadCell,
DateRangePickerHeader,
DateRangePickerHeading,
DateRangePickerInput,
DateRangePickerNext,
DateRangePickerPrev,
DateRangePickerRoot,
DateRangePickerTrigger,
} from 'reka-ui'
</script>
<template>
<DateRangePickerRoot>
<DateRangePickerField>
<DateRangePickerInput />
<DateRangePickerTrigger />
</DateRangePickerField>
<DateRangePickerAnchor />
<DateRangePickerContent>
<DateRangePickerClose />
<DateRangePickerArrow />
<DateRangePickerCalendar>
<DateRangePickerHeader>
<DateRangePickerPrev />
<DateRangePickerHeading />
<DateRangePickerNext />
</DateRangePickerHeader>
<DateRangePickerGrid>
<DateRangePickerGridHead>
<DateRangePickerGridRow>
<DateRangePickerHeadCell />
</DateRangePickerGridRow>
</DateRangePickerGridHead>
<DateRangePickerGridBody>
<DateRangePickerGridRow>
<DateRangePickerCell>
<DateRangePickerCellTrigger />
</DateRangePickerCell>
</DateRangePickerGridRow>
</DateRangePickerGridBody>
</DateRangePickerGrid>
</DateRangePickerCalendar>
</DateRangePickerContent>
</DateRangePickerRoot>
</template>API Reference
Root
Contains all the parts of a date picker
Field
Contains the date picker date field segments and trigger
| Data Attribute | Value |
|---|---|
[data-readonly] | Present when readonly |
[data-disabled] | Present when disabled |
[data-invalid] | Present when invalid |
Input
Contains the date picker date field segments
| Data Attribute | Value |
|---|---|
[data-disabled] | Present when disabled |
[data-invalid] | Present when invalid |
[data-placeholder] | Present when no value is set |
Trigger
The button that toggles the popover. By default, the DateRangePickerContent will position itself against the trigger.
Content
The component that pops out when the popover is open.
Arrow
An optional arrow element to render alongside the popover. This can be used to help visually link the anchor with the DateRangePickerContent. Must be rendered inside DateRangePickerContent.
Close
The button that closes an open date picker.
Anchor
An optional element to position the DateRangePickerContent against. If this part is not used, the content will position alongside the DateRangePickerTrigger.
Calendar
Contains all the parts of a calendar
| Data Attribute | Value |
|---|---|
[data-readonly] | Present when readonly |
[data-disabled] | Present when disabled |
[data-invalid] | Present when invalid |
Header
Contains the navigation buttons and the heading segments.
Prev Button
Calendar navigation button. It navigates the calendar one month/year/decade in the past based on the current calendar view.
| Data Attribute | Value |
|---|---|
[data-disabled] | Present when disabled |
Next Button
Calendar navigation button. It navigates the calendar one month/year/decade in the future based on the current calendar view.
| Data Attribute | Value |
|---|---|
[data-disabled] | Present when disabled |
Heading
Heading for displaying the current month and year
| Data Attribute | Value |
|---|---|
[data-disabled] | Present when disabled |
Grid
Container for wrapping the calendar grid.
| Data Attribute | Value |
|---|---|
[data-readonly] | Present when readonly |
[data-disabled] | Present when disabled |
Grid Head
Container for wrapping the grid head.
Grid Body
Container for wrapping the grid body.
Grid Row
Container for wrapping the grid row.
Head Cell
Container for wrapping the head cell. Used for displaying the week days.
Cell
Container for wrapping the calendar cells.
| Data Attribute | Value |
|---|---|
[data-disabled] | Present when disabled |
Cell Trigger
Interactable container for displaying the cell dates. Clicking it selects the date.
| Data Attribute | Value |
|---|---|
[data-selected] | Present when selected |
[data-value] | The ISO string value of the date. |
[data-disabled] | Present when disabled |
[data-unavailable] | Present when unavailable |
[data-today] | Present when today |
[data-outside-view] | Present when the date is outside the current month it is displayed in. |
[data-outside-visible-view] | Present when the date is outside the months that are visible on the calendar. |
[data-selection-start] | Present when the date is the start of the selection. |
[data-selection-end] | Present when the date is the end of the selection. |
[data-highlighted] | Present when the date is highlighted by the user as they select a range. |
[data-highlighted-start] | Present when the date is the start of the range that is highlighted by the user. |
[data-highlighted-end] | Present when the date is the end of the range that is highlighted by the user. |
[data-focused] | Present when focused |
Accessibility
Keyboard Interactions
| Key | Description |
|---|---|
Tab | When focus moves onto the date field, focuses the first segment. |
Space |
When the focus is on either DateRangePickerNext or DateRangePickerPrev, it navigates the calendar. Otherwise, it selects the date. If the focus is on DateRangePickerTrigger, it opens/closes the popover.
|
Enter |
When the focus is on either DateRangePickerNext or DateRangePickerPrev, it navigates the calendar. Otherwise, it selects the date. If the focus is on DateRangePickerTrigger, it opens/closes the popover.
|
ArrowLeftArrowRight |
Navigates between the date field segments. If the focus is on the DateRangePickerCalendar, it navigates between the dates.
|
ArrowUpArrowDown | Increments/changes the value of the segment. If the focus is on the DateRangePickerCalendar, it navigates between the dates. |
0-9 |
When the focus is on a numeric DateRangePickerInput, it types in the number and focuses the next segment if the next input would result in an invalid value.
|
Backspace | Deletes a digit from the focused numeric segments. |
AP | When the focus is on the day period, it sets it to AM or PM. |
