Year Range Picker
2020 | 2021 | 2022 | 2023 |
2024 | 2025 | 2026 | 2027 |
2028 | 2029 | 2030 | 2031 |
Features
- Full keyboard navigation
- Can be controlled or uncontrolled
- Focus is fully managed
- Localization support
- Highly composable
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 {
YearRangePickerCell,
YearRangePickerCellTrigger,
YearRangePickerGrid,
YearRangePickerGridBody,
YearRangePickerGridRow,
YearRangePickerHeader,
YearRangePickerHeading,
YearRangePickerNext,
YearRangePickerPrev,
YearRangePickerRoot,
} from 'reka-ui'
</script>
<template>
<YearRangePickerRoot>
<YearRangePickerHeader>
<YearRangePickerPrev />
<YearRangePickerHeading />
<YearRangePickerNext />
</YearRangePickerHeader>
<YearRangePickerGrid>
<YearRangePickerGridBody>
<YearRangePickerGridRow>
<YearRangePickerCell>
<YearRangePickerCellTrigger />
</YearRangePickerCell>
</YearRangePickerGridRow>
</YearRangePickerGridBody>
</YearRangePickerGrid>
</YearRangePickerRoot>
</template>API Reference
Root
Contains all the parts of a year range picker
| 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 page (12 years by default) in the past.
| Data Attribute | Value |
|---|---|
[data-disabled] | Present when disabled |
Next Button
Calendar navigation button. It navigates the calendar one page (12 years by default) in the future.
| Data Attribute | Value |
|---|---|
[data-disabled] | Present when disabled |
Heading
Heading for displaying the current year range.
| Data Attribute | Value |
|---|---|
[data-disabled] | Present when disabled |
Grid
Container for wrapping the year range picker grid.
| Data Attribute | Value |
|---|---|
[data-readonly] | Present when readonly |
[data-disabled] | Present when disabled |
Grid Body
Container for wrapping the grid body.
Grid Row
Container for wrapping the grid row.
Cell
Container for wrapping the year range picker cells.
| Data Attribute | Value |
|---|---|
[data-disabled] | Present when disabled |
Cell Trigger
Interactable container for displaying the cell years. Clicking it selects the year.
| 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 the year is the current year |
[data-selection-start] | Present when the year is the start of the selection. |
[data-selection-end] | Present when the year is the end of the selection. |
[data-highlighted] | Present when the year is highlighted by the user as they select a range. |
[data-highlighted-start] | Present when the year is the start of the range that is highlighted by the user. |
[data-highlighted-end] | Present when the year 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 year range picker, focuses the first navigation button. |
Space |
When the focus is on either YearRangePickerNext or YearRangePickerPrev, it navigates the calendar. Otherwise, it selects the year.
|
Enter |
When the focus is on either YearRangePickerNext or YearRangePickerPrev, it navigates the calendar. Otherwise, it selects the year.
|
ArrowLeftArrowRightArrowUpArrowDown |
When the focus is on YearRangePickerCellTrigger, it navigates the years, changing the page if necessary.
|
PageUp | When the focus is on YearRangePickerCellTrigger, it navigates to the previous page of years. |
PageDown | When the focus is on YearRangePickerCellTrigger, it navigates to the next page of years. |
Escape | Cancels the current range selection and restores the previous valid range. |
