1. Components
  2. Date and time
  3. Calendar

Calendar

A component that allows users to select a single date.

Appointment date, February 2025

26
27
28
29
30
31
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
1
<Calendar aria-label="Appointment date" />

Installation

npx dotui-cli@latest add calendar

Usage

Use Calendar to allow users to select a single date.

import { parseDate } from "@internationalized/date";
import { Calendar } from "@/components/core/calendar";
 
<Calendar
  aria-label="Appointment date"
  defaultValue={parseDate("2025-01-01")}
/>;
import { parseDate } from "@internationalized/date";
import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react";
import { Button } from "@/components/core/button";
import {
  CalendarRoot,
  CalendarHeader,
  CalendarGrid,
  CalendarGridHeader,
  CalendarHeaderCell,
  CalendarGridBody,
  CalendarCell,
} from "@/components/core/calendar";
import { Heading } from "@/registry/ui/default/core/heading";
 
<CalendarRoot
  aria-label="Appointment date"
  defaultValue={parseDate("2025-01-01")}
>
  <CalendarHeader>
    <Button slot="previous">
      <ChevronLeftIcon />
    </Button>
    <Heading />
    <Button slot="next">
      <ChevronRightIcon />
    </Button>
  </CalendarHeader>
  <CalendarGrid>
    <CalendarGridHeader>
      {(day) => <CalendarHeaderCell>{day}</CalendarHeaderCell>}
    </CalendarGridHeader>
    <CalendarGridBody>
      {(date) => <CalendarCell date={date} />}
    </CalendarGridBody>
  </CalendarGrid>
</CalendarRoot>;

Best practices

  • An aria-label must be provided to the Calendar for accessibility. If it is labeled by a separate element, an aria-labelledby prop must be provided using the id of the labeling element instead.

Uncontrolled

An initial, uncontrolled value can be provided to the Calendar using the defaultValue prop.

Appointment date, February 2020

26
27
28
29
30
31
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
<Calendar aria-label="Appointment date" defaultValue={parseDate("2025-01-01")} />

Controlled

The Calendar component can be controlled by passing the value and onChange props.

Event date, January 2025

29
30
31
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

Selected date: 2025-01-01

const [value, setValue] = React.useState<DateValue>(parseDate('2025-01-01'))
return <Calendar aria-label="Event date" value={value} onChange={setValue} />

Validation

Min and max values

By default, Calendar allows selecting any date. The minValue and maxValue props can also be used to prevent the user from selecting dates outside a certain range.

This example only accepts dates after today.

Appointment date, February 2025

26
27
28
29
30
31
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
1
<Calendar aria-label="Appointment date" minValue={today(getLocalTimeZone())} />

Unavailable dates

Calendar supports marking certain dates as unavailable. These dates cannot be selected by the user and are displayed with a crossed out appearance. The isDateUnavailable prop accepts a callback that is called to evaluate whether each visible date is unavailable.

This example includes multiple unavailable date ranges, e.g. dates when no appointments are available. In addition, all weekends are unavailable. The minValue prop is also used to prevent selecting dates before today.

Appointment date, February 2025

26
27
28
29
30
31
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
1
const now = today(getLocalTimeZone());
const disabledRanges = [
  [now, now.add({ days: 5 })],
  [now.add({ days: 14 }), now.add({ days: 16 })],
  [now.add({ days: 23 }), now.add({ days: 24 })],
];

const { locale } = useLocale();
const isDateUnavailable = (date: DateValue) =>
  isWeekend(date, locale) ||
  disabledRanges.some(
    (interval) => date.compare(interval[0]) >= 0 && date.compare(interval[1]) <= 0
  );

return (
  <Calendar
    minValue={today(getLocalTimeZone())}
    isDateUnavailable={isDateUnavailable}
  />
);

Error message

Calendar tries to avoid allowing the user to select invalid dates in the first place (see Min and max values and Unavailable dates. However, if according to application logic a selected date is invalid, Use isInvalid and errorMessage props.

This example validates that the selected date is a weekday and not a weekend according to the current locale.

Appointment date, February 2025

26
27
28
29
30
31
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
1
We are closed on weekends
const [date, setDate] = React.useState(today(getLocalTimeZone()));
const { locale } = useLocale();
const isInvalid = isWeekend(date, locale);
return (
  <Calendar
    aria-label="Appointment date"
    value={date}
    onChange={setDate}
    isInvalid={isInvalid}
    errorMessage={"We are closed on weekends"}
  />

);

Options

Variant

The variant prop can be used to change the appearance of the Calendar.

Appointment date, January 2025

29
30
31
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
<Calendar
  aria-label="Appointment date"
  variant="primary"
  defaultValue={parseDate("2025-01-01")}
/>

Visible months

By default, Calendar displays a single month. The visibleMonths prop allows displaying up to 3 months at a time.

Appointment date, February to March 2025

26
27
28
29
30
31
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
1
23
24
25
26
27
28
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
<Calendar aria-label="Appointment date" visibleMonths={2} />

Page behaviour

The pageBehavior prop allows you to control how the calendar navigates between months.

Appointment date, February to March 2025

26
27
28
29
30
31
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
1
23
24
25
26
27
28
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
<Calendar aria-label="Appointment date" visibleMonths={2} pageBehavior="single" />

Disabled

The isDisabled boolean prop makes the Calendar disabled. Cells cannot be focused or selected.

Appointment date, February 2025

26
27
28
29
30
31
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
1
<Calendar aria-label="Appointment date" isDisabled />

Read only

The isReadOnly boolean prop makes the Calendar's value immutable. Unlike isDisabled, the Calendar remains focusable.

Appointment date, February 2025

26
27
28
29
30
31
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
1
<Calendar aria-label="Appointment date" isReadOnly value={today(getLocalTimeZone())} />

Composition

If you need to customize things further, you can drop down to the composition level.

Event date, February 2025

26
27
28
29
30
31
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
1
<CalendarRoot aria-label="Event date">
  <CalendarHeader>
    <Button slot="previous">
      <ChevronLeftIcon />
    </Button>
    <Heading />
    <Button slot="next">
      <ChevronRightIcon />
    </Button>
  </CalendarHeader>
  <CalendarGrid>
    <CalendarGridHeader>
      {(day) => <CalendarHeaderCell>{day}</CalendarHeaderCell>}
    </CalendarGridHeader>
    <CalendarGridBody>
      {(date) => <CalendarCell date={date} />}
    </CalendarGridBody>
  </CalendarGrid>
</CalendarRoot>

API Reference

PropTypeDefaultDescription
visibleMonthsnumber1The number of months to display at once. Up to 3 months are supported.
minValueDateValue-The minimum allowed date that a user may select.
maxValueDateValue-The maximum allowed date that a user may select.
isDateUnavailable(date: DateValue) => boolean-Callback that is called for each date of the calendar. If it returns true, then the date is unavailable.
isDisabledbooleanfalseWhether the calendar is disabled.
isReadOnlybooleanfalseWhether the calendar value is immutable.
autoFocusbooleanfalseWhether to automatically focus the calendar when it mounts.
focusedValueDateValue-Controls the currently focused date within the calendar.
defaultFocusedValueDateValue-The date that is focused when the calendar first mounts (uncountrolled).
isInvalidboolean-Whether the current selection is invalid according to application logic.
pageBehavior'single' | 'visible''visible'Controls the behavior of paging. Pagination either works by advancing the visible page by visibleDuration (default) or one unit of visibleDuration.
valueDateValue | null-The current value (controlled).
defaultValueDateValue | null-The default value (uncontrolled).
childrenReactNode | (values: CalendarRenderProps & {defaultChildren: ReactNode | undefined}) => ReactNode-The children of the component. A function may be provided to alter the children based on component state.
classNamestring-The CSS className for the element.
styleCSSProperties | (values: CalendarRenderProps & {defaultStyle: CSSProperties}) => CSSProperties-The inline style for the element. A function may be provided to compute the style based on component state.
EventTypeDescription
onFocusChange(date: CalendarDate) => voidHandler that is called when the focused date changes.
onChange(value: MappedDateValue<DateValue>) => voidHandler that is called when the value changes.

Accessibility

Keyboard interactions

KeyDescription
TabMoves focus to the next focusable item in the calendar.
Shift+TabMoves focus to the previous focusable item in the calendar.
ArrowRightMoves focus to the next day.
ArrowLeftMoves focus to the previous day.
ArrowDownMoves focus to the same day of the week in the next week.
ArrowUpMoves focus to the same day of the week in the previous week.
Space EnterSelects the focused date.
dotUI

Bringing singularity to the web.

Built by mehdibha. The source code is available on GitHub.