Range Calendar
| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 1 | 2 | 3 | 4 | 5 |
6 | 7 | 8 | 9 | 10 | 11 | 12 |
Features
- Full keyboard navigation
- Can be controlled or uncontrolled
- Focus is fully managed
- Localization support
- Highly composable
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 {
RangeCalendarCell,
RangeCalendarCellTrigger,
RangeCalendarGrid,
RangeCalendarGridBody,
RangeCalendarGridHead,
RangeCalendarGridRow,
RangeCalendarHeadCell,
RangeCalendarHeader,
RangeCalendarNext,
RangeCalendarPrev,
RangeCalendarRoot,
RangeCalendarView,
RangeCalendarViewTrigger,
} from 'reka-ui'
</script>
<template>
<RangeCalendarRoot>
<RangeCalendarHeader>
<RangeCalendarPrev />
<RangeCalendarViewTrigger />
<RangeCalendarNext />
</RangeCalendarHeader>
<RangeCalendarView view="day">
<RangeCalendarGrid>
<RangeCalendarGridHead>
<RangeCalendarGridRow>
<RangeCalendarHeadCell />
</RangeCalendarGridRow>
</RangeCalendarGridHead>
<RangeCalendarGridBody>
<RangeCalendarGridRow>
<RangeCalendarCell>
<RangeCalendarCellTrigger />
</RangeCalendarCell>
</RangeCalendarGridRow>
</RangeCalendarGridBody>
</RangeCalendarGrid>
</RangeCalendarView>
</RangeCalendarRoot>
</template>RangeCalendarView and RangeCalendarViewTrigger are optional. A calendar that only ever shows one unit (the default day grid, or a month or year range picker via granularity) can put RangeCalendarGrid straight under the root and use RangeCalendarHeading in place of the trigger for a static heading; the two render the same text, so use one or the other.
API Reference
Root
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 root's view matches, and tells the cells inside which unit they render. Optional: a single-view calendar can place RangeCalendarGrid directly under the root.
View Trigger
The heading as a button. Each press switches to the next coarser view (day → month → year) up to maxView; selecting a cell in a coarser view drills back down without touching the range. The coarser views apply only minValue / maxValue: isDateDisabled, isDateUnavailable, isDateHighlightable and the root nextPage / prevPage run in the granularity view.
| Data Attribute | Value |
|---|---|
[data-view] | "day" | "month" | "year" |
[data-disabled] | Present when disabled or at maxView |
Examples
Month range picker
Set granularity="month" to select a range of months. maximumLength caps the range in months.
Jan | Feb | Mar | Apr |
May | Jun | Jul | Aug |
Sep | Oct | Nov | Dec |
Year range picker
Set granularity="year" to select a range of years.
2020 | 2021 | 2022 | 2023 |
2024 | 2025 | 2026 | 2027 |
2028 | 2029 | 2030 | 2031 |
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 calendar, focuses the first navigation button. |
Space |
When the focus is on either RangeCalendarNext or RangeCalendarPrev, it navigates the calendar. Otherwise, it selects the date.
|
Enter |
When the focus is on either RangeCalendarNext or RangeCalendarPrev, it navigates the calendar. Otherwise, it selects the date.
|
ArrowLeftArrowRightArrowUpArrowDown |
When the focus is on RangeCalendarCellTrigger, it moves by one cell or one row (a week of days, or a row of months / years), changing the page if necessary.
|
Home |
When the focus is on RangeCalendarCellTrigger, in the day view, it moves focus to the first day of the current week. In the month and year views, it moves focus to the first month or year of the current page, skipping disabled cells and cells outside minValue / maxValue.
|
End |
When the focus is on RangeCalendarCellTrigger, in the day view, it moves focus to the last day of the current week. In the month and year views, it moves focus to the last month or year of the current page, skipping disabled cells and cells outside minValue / maxValue.
|
PageUp |
When the focus is on RangeCalendarCellTrigger, in the day view, it moves to the previous month while preserving the day of the month when possible, or clamps to the last day of the month. In the month and year views, it moves to the same cell on the previous page.
|
PageDown |
When the focus is on RangeCalendarCellTrigger, in the day view, it moves to the next month while preserving the day of the month when possible, or clamps to the last day of the month. In the month and year views, it moves to the same cell on the next page.
|
Shift+PageUp |
When the focus is on RangeCalendarCellTrigger, in the day view, it moves to the previous year while preserving the month and day when possible, or clamps to the last day of the month.
|
Shift+PageDown |
When the focus is on RangeCalendarCellTrigger, in the day view, it moves to the next year while preserving the month and day when possible, or clamps to the last day of the month.
|
In a right-to-left layout (dir="rtl" on RangeCalendarRoot, or on a ConfigProvider), ArrowLeft moves to the next day and ArrowRight to the previous day; in the month and year views, to the next or previous month or year. See Internationalization.
Headless composable
useRangeCalendar is the range counterpart of useCalendar: it adds startValue / endValue, the highlightedRange while the user picks the end, abortEditing(), and the range options (allowNonContiguousRanges, maximumLength, fixedDate, isDateHighlightable). It registers watchers, so call it inside setup(). The composable is experimental; see Headless composables.
