Month Picker
Jan | Feb | Mar | Apr |
May | Jun | Jul | Aug |
Sep | Oct | Nov | Dec |
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 {
MonthPickerCell,
MonthPickerCellTrigger,
MonthPickerGrid,
MonthPickerGridBody,
MonthPickerGridRow,
MonthPickerHeader,
MonthPickerHeading,
MonthPickerNext,
MonthPickerPrev,
MonthPickerRoot,
} from 'reka-ui'
</script>
<template>
<MonthPickerRoot>
<MonthPickerHeader>
<MonthPickerPrev />
<MonthPickerHeading />
<MonthPickerNext />
</MonthPickerHeader>
<MonthPickerGrid>
<MonthPickerGridBody>
<MonthPickerGridRow>
<MonthPickerCell>
<MonthPickerCellTrigger />
</MonthPickerCell>
</MonthPickerGridRow>
</MonthPickerGridBody>
</MonthPickerGrid>
</MonthPickerRoot>
</template>API Reference
Root
Contains all the parts of a month 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 year in the past.
| Data Attribute | Value |
|---|---|
[data-disabled] | Present when disabled |
Next Button
Calendar navigation button. It navigates the calendar one year in the future.
| Data Attribute | Value |
|---|---|
[data-disabled] | Present when disabled |
Heading
Heading for displaying the current year.
| Data Attribute | Value |
|---|---|
[data-disabled] | Present when disabled |
Grid
Container for wrapping the month 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 month picker cells.
| Data Attribute | Value |
|---|---|
[data-disabled] | Present when disabled |
Cell Trigger
Interactable container for displaying the cell months. Clicking it selects the month.
| 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 month is the current month |
[data-focused] | Present when focused |
Accessibility
Keyboard Interactions
| Key | Description |
|---|---|
Tab | When focus moves onto the month picker, focuses the first navigation button. |
Space |
When the focus is on either MonthPickerNext or MonthPickerPrev, it navigates the calendar. Otherwise, it selects the month.
|
Enter |
When the focus is on either MonthPickerNext or MonthPickerPrev, it navigates the calendar. Otherwise, it selects the month.
|
ArrowLeftArrowRightArrowUpArrowDown |
When the focus is on MonthPickerCellTrigger, it navigates the months, changing the year if necessary.
|
PageUp | When the focus is on MonthPickerCellTrigger, it navigates to the same month in the previous year. |
PageDown | When the focus is on MonthPickerCellTrigger, it navigates to the same month in the next year. |
