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 works with the Temporal API: its values are Temporal.PlainDate, Temporal.PlainDateTime or Temporal.ZonedDateTime. Reka UI does not bundle a Temporal implementation, so on runtimes without native Temporal your app loads a polyfill. See Dates & Times for the setup and how the components treat calendars and time zones.
Installation
On runtimes without native Temporal, install a polyfill and load it once, before the app mounts.
$ npm add temporal-polyfill-lite// main.ts
import { install } from 'temporal-polyfill-lite/shim'
install(false) // keeps the native Temporal when the browser has oneInstall 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. A trigger that holds only an icon has no accessible name, so give it an aria-label (for example aria-label="Open calendar").
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 |
View
Renders its content only while the calendar's view matches. Wrap each of the day, month and year grids in one to let users drill between them; a picker that only shows the day grid can omit it.
View Trigger
The calendar heading as a button that switches to the next coarser view (day → month → year) up to maxView. Selecting a cell in a coarser view drills back down without changing the value or closing the popover.
Real-world examples
- Date Range Presets: Pair a RangeCalendar with the analytics presets people actually reach for — last 7 days, month to date, year to date.
- Date Picker Selection: Date pickers let users select a date or a range of dates. They commonly use in booking systems.
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. |
Headless composable
useDateRangePicker owns the range, the placeholder, the open state and the view, and returns getFieldProps() and getCalendarProps(): the options that make a useDateRangeField and a useRangeCalendar its field and its calendar, plus the popover state. Positioning and focus management stay in the components. It registers watchers, so call it inside setup(). The composable is experimental; see Headless composables.
