Reka UI logoReka
backdrop
Components

Calendar

Displays dates and days of the week, facilitating date-related interactions.
October 2024
29
30
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
31
1
2
3
4
5
6
7
8
9
Event Date, October 2024

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.

sh
$ npm add temporal-polyfill-lite
ts
// main.ts
import { install } from 'temporal-polyfill-lite/shim'

install(false) // keeps the native Temporal when the browser has one

Install the component from your command line.

sh
$ npm add reka-ui

Anatomy

Import all parts and piece them together.

vue
<script setup>
import {
  CalendarCell,
  CalendarCellTrigger,
  CalendarGrid,
  CalendarGridBody,
  CalendarGridHead,
  CalendarGridRow,
  CalendarHeadCell,
  CalendarHeader,
  CalendarNext,
  CalendarPrev,
  CalendarRoot,
  CalendarView,
  CalendarViewTrigger,
} from 'reka-ui'
</script>

<template>
  <CalendarRoot>
    <CalendarHeader>
      <CalendarPrev />
      <CalendarViewTrigger />
      <CalendarNext />
    </CalendarHeader>
    <CalendarView view="day">
      <CalendarGrid>
        <CalendarGridHead>
          <CalendarGridRow>
            <CalendarHeadCell />
          </CalendarGridRow>
        </CalendarGridHead>
        <CalendarGridBody>
          <CalendarGridRow>
            <CalendarCell>
              <CalendarCellTrigger />
            </CalendarCell>
          </CalendarGridRow>
        </CalendarGridBody>
      </CalendarGrid>
    </CalendarView>
  </CalendarRoot>
</template>

CalendarView and CalendarViewTrigger are optional. A calendar that only ever shows one unit (the default day grid, or a month or year picker via granularity) can put CalendarGrid straight under the root and use CalendarHeading 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 AttributeValue
[data-readonly]Present when readonly
[data-disabled]Present when disabled
[data-invalid]Present when invalid

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 AttributeValue
[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 AttributeValue
[data-disabled]Present when disabled

Heading

Heading for displaying the current month and year

Data AttributeValue
[data-disabled]Present when disabled

Grid

Container for wrapping the calendar grid.

Data AttributeValue
[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 AttributeValue
[data-disabled]Present when disabled

Cell Trigger

Interactable container for displaying the cell dates. Clicking it selects the date.

Data AttributeValue
[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-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 CalendarGrid 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.

Data AttributeValue
[data-view]"day" | "month" | "year"
[data-disabled]Present when disabled or at maxView

Examples

Month picker

Set granularity="month" to commit months instead of days. The grid then holds the twelve months of the placeholder's year, columns per row, and Prev / Next move a year at a time. The selected value keeps the placeholder's day.

2024
Jan
Feb
Mar
Apr
May
Jun
Jul
Aug
Sep
Oct
Nov
Dec
Month Picker, 2024

Year picker

Set granularity="year". The grid holds yearsPerPage years starting at the placeholder's decade, and Prev / Next move a page at a time.

2020 - 2031
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
Year Picker, 2020 - 2031

Day, month and year views

Wrap each grid in a CalendarView and put a CalendarViewTrigger in the header to let users drill from the day grid up to the month and year grids and back. See the view switching example.

The month and year views of a day calendar are navigation: isDateDisabled, isDateUnavailable and the root nextPage / prevPage apply only in the granularity view, so the coarser cells are limited by minValue and maxValue alone and show no selection.

Calendar with Year Incrementation

This example showcases a calendar which allows incrementing the year.

November 2026
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
Event Date, November 2026

Calendar with Locale and Calendar System Selection

This example showcases some of the available locales and how the calendar systems are displayed.

November 2026
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
Event Date, November 2026

Calendar swipe gesture navigation

This component demonstrates intuitive calendar navigation using touch-based swipe gestures, user-friendly way to browse through months.

January 2023
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
31
1
2
3
4
5
6
7
8
9
10
11
Event Date, January 2023

Calendar week numbers

This example showcases usage of the CalendarWeek component used to display the number of the week.

November 2026
45
46
47
48
49
50
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
Event Date, November 2026

Real-world examples

  • Date Picker View Switching: One Calendar with day, month and year views: click the heading to drill up, select a cell to drill back down.
  • Date Picker Selection: Date pickers let users select a date or a range of dates. They commonly use in booking systems.

Accessibility

Keyboard Interactions

KeyDescription
Tab
When focus moves onto the calendar, focuses the first navigation button.
Space
When the focus is on either CalendarNext or CalendarPrev, it navigates the calendar. Otherwise, it selects the date.
Enter
When the focus is on either CalendarNext or CalendarPrev, it navigates the calendar. Otherwise, it selects the date.
ArrowLeftArrowRightArrowUpArrowDown
When the focus is on CalendarCellTrigger, 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 CalendarCellTrigger, 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 CalendarCellTrigger, 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 CalendarCellTrigger, 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 CalendarCellTrigger, 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 CalendarCellTrigger, 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 CalendarCellTrigger, 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 CalendarRoot, 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

useCalendar holds the value, the placeholder (the month shown) and the view (modelValue, placeholder, view, select(), setPlaceholder(), setView(), drillUp(), nextPage(), prevPage()), builds the grid and weekDays, applies minValue, maxValue, isDateDisabled and isDateUnavailable, and returns the root, heading, viewTrigger, prev and next part surfaces with getGridSurface(), getCellSurface() and getCellTriggerSurface(). It registers watchers, so call it inside setup(). The composable is experimental; see Headless composables.