Calendar
A month grid for picking one day, several days or a range of days, always on screen. To pick a date inside a form field use the date picker, which opens this grid from a field; for a range with presets use the date range picker; for a strip of one week use the mini calendar.
Install
npx shadcn@latest add https://thrumui.dev/r/calendar.jsonAdds components/ui/calendar.tsx. Nothing else in your project changes.
import { makeDate } from "@/components/ui/calendar";Automatically installs icons chevron-left and chevron-right from the icon set.
Data shape
// mode="single" holds a Date or null, mode="multiple" a Date[], mode="range" this:
type DateRange = { from: Date | null; to: Date | null };const value: DateRange = {
from: new Date(2026, 11, 3),
to: new Date(2026, 11, 9),
};Props
| Prop | Type | Default | Description |
|---|---|---|---|
mode | "single" | "multiple" | "range" | Default "single" | One day, any number of days, or a range from one day to another. It sets the type of value. |
value | Date | null, Date[] or DateRange | – | The picked days, when the parent holds them. Use it with onValueChange. |
defaultValue | Date | null, Date[] or DateRange | – | The days picked at first, when the calendar holds them itself. |
onValueChange | (value) => void | – | Called with the new value after each press. In range mode the first press gives a range whose to is null. |
month | Date | – | The month on screen (any day in it), when the parent holds it. Use it with onMonthChange. |
defaultMonth | Date | – | The month shown first. Defaults to the month of the first picked day, then the month of today. |
onMonthChange | (month: Date) => void | – | Called with the 1st of the month when the visitor moves to another month. |
numberOfMonths | number | Default 1 | Months shown side by side, 224 pixels each. They wrap onto a new line when there is no room. |
min | Date | null | – | The earliest day that can be picked. The previous-month button stops at its month. |
max | Date | null | – | The latest day that can be picked. The next-month button stops at its month. |
disabledDays | Date[] | { dayOfWeek: number[] } | – | Days that cannot be picked: a list of dates, or weekdays where 0 is Sunday ({ dayOfWeek: [0, 6] } for weekends). |
disabled | boolean | Default false | The whole calendar is dimmed and cannot be changed or focused. |
maxDays | number | – | Range mode: the longest range in days, both ends counted. Once the first end is picked, days further away cannot be picked. |
weekStartsOn | 0 | 1 | 2 | 3 | 4 | 5 | 6 | – | The weekday of the first column, 0 for Sunday. Defaults to the locale's week from the browser, else Monday. |
locale | string | Default "en-US" | The language of the month and weekday names. |
showOutsideDays | boolean | Default true | Show the days of the months before and after that complete the first and last week. A press on one picks it and turns the page. They never show a selection. |
captionLayout | "label" | "dropdown" | Default "label" | dropdown replaces the month name with a month and a year select. The years run from min to max, or 100 years back and 10 ahead. |
today | Date | – | The day marked as today. The calendar never reads the clock, so server and browser draw the same grid. |
sound | boolean | Default true | Play a click when a day is picked, if the visitor has sound on. |
surface | boolean | Default true | Paint the calendar's own rounded panel border and padding. Pass false when embedded inside a popover. |
className | string | – | Extra classes for the root, merged last. |
Motion and sound
Motion
- Turning to another month slides the grid 8 pixels from the direction of travel and fades in over 180 ms; a day's colour fades over 150 ms when picked or hovered.
- Reduced motion: the month and day colours change at once.
Sound
- A click when a day is picked or unpicked. Turning the month is silent.
Sound is off until the visitor turns it on. Pass sound={false} to keep this component silent. How sound works
Accessibility
- It follows the WAI-ARIA date grid pattern: each month is a grid named by its caption, with one tab stop that the arrow keys move.
- Each day is a button named by its full date (Thursday, December 3, 2026). The picked days carry aria-selected and today carries aria-current.
- A picked day is filled and the days between the ends of a range are banded, so selection does not rest on colour alone. Today has a dot under its number.
- Days that cannot be picked keep their place in the arrow-key path, carry aria-disabled, and are struck through.
- The month name is a polite live region, so a screen reader announces the new month when the page turns.
- The arrow keys follow the reading direction: in right-to-left text, ← moves to the next day.
- The grid needs 224 pixels; a narrower container keeps that width.
| Keys | Action |
|---|---|
| Tab | Move into the grid, onto the picked day, today or the 1st. Tab again leaves it. |
| ← / → | The previous or next day. The month turns when the focus leaves it. |
| ↑ / ↓ | The same weekday a week earlier or later. |
| Home / End | The first or last day of the week. |
| Page Up / Page Down | The same day in the previous or next month. |
| Shift Page Up / Shift Page Down | The same day in the previous or next year. |
| Enter / Space | Pick the focused day, or in multiple mode unpick it. |
Source
"use client";
import { useEffect, useId, useRef, useState, type ComponentProps, type KeyboardEvent } from "react";
import { cn } from "@/lib/utils";
import { ChevronLeftIcon } from "@/components/icons/chevron-left";
import { ChevronRightIcon } from "@/components/icons/chevron-right";
import { play } from "@/lib/thrum-sound";
import { IconButton } from "@/components/ui/icon-button";
import { NativeSelect, NativeSelectOption } from "@/components/ui/native-select";
// ---------------------------------------------------------------------------------------------------------------
// Date maths. A date is a plain `Date` at local midnight, read through its calendar fields. Days are added through the
// calendar fields too, never as milliseconds, so a daylight saving change can never move a date by a day.
// The other date components import these.
// ---------------------------------------------------------------------------------------------------------------
/** A weekday: 0 is Sunday, 6 is Saturday, as `Date.getDay()` counts. */
export type Weekday = 0 | 1 | 2 | 3 | 4 | 5 | 6;
/** A range of days. `to` is null while only the first end is picked. */
export type DateRange = { from: Date | null; to: Date | null };
/** Days that cannot be picked: a list of dates, or weekdays (`{ dayOfWeek: [0, 6] }` for weekends). */
export type DisabledDays = readonly Date[] | { dayOfWeek: readonly number[] };
/** A date at midnight. Unlike `new Date(y, m, d)` it keeps years below 100, and it rolls over like the constructor. */
export function makeDate(year: number, month: number, day: number): Date {
const date = new Date(2000, 0, 1);
date.setFullYear(year, month, day);
return date;
}
export const startOfDay = (date: Date): Date => makeDate(date.getFullYear(), date.getMonth(), date.getDate());
export const addDays = (date: Date, days: number): Date => makeDate(date.getFullYear(), date.getMonth(), date.getDate() + days);
export const startOfMonth = (date: Date): Date => makeDate(date.getFullYear(), date.getMonth(), 1);
export const endOfMonth = (date: Date): Date => makeDate(date.getFullYear(), date.getMonth() + 1, 0);
/** Days in a month, 28 to 31. `month` is 0 to 11. */
export const daysInMonth = (year: number, month: number): number => makeDate(year, month + 1, 0).getDate();
/** The same day `months` later. A day the target month lacks becomes its last day: 31 January plus one month is 28 or 29 February. */
export function addMonths(date: Date, months: number): Date {
const first = makeDate(date.getFullYear(), date.getMonth() + months, 1);
return makeDate(first.getFullYear(), first.getMonth(), Math.min(date.getDate(), daysInMonth(first.getFullYear(), first.getMonth())));
}
/** Negative when `a` is the earlier day, 0 on the same day, positive when later. The time of day is ignored. */
export const compareDays = (a: Date, b: Date): number => a.getFullYear() - b.getFullYear() || a.getMonth() - b.getMonth() || a.getDate() - b.getDate();
export const isSameDay = (a: Date | null | undefined, b: Date | null | undefined): boolean => Boolean(a && b && compareDays(a, b) === 0);
export const isSameMonth = (a: Date, b: Date): boolean => a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth();
/** Whole days from `a` to `b`: 1 for the next day, -1 for the day before. */
export function differenceInDays(a: Date, b: Date): number {
// Both at UTC midnight, where every day is 24 hours long.
return Math.round((Date.UTC(b.getFullYear(), b.getMonth(), b.getDate()) - Date.UTC(a.getFullYear(), a.getMonth(), a.getDate())) / 86_400_000);
}
/** The first day of the week that holds `date`. */
export const startOfWeek = (date: Date, weekStartsOn: Weekday): Date => addDays(date, -((date.getDay() - weekStartsOn + 7) % 7));
/** The day closest to `date` that lies between `min` and `max`. */
export function clampDay(date: Date, min?: Date | null, max?: Date | null): Date {
if (min && compareDays(date, min) < 0) return startOfDay(min);
if (max && compareDays(date, max) > 0) return startOfDay(max);
return date;
}
/** Six weeks of seven days that cover the month, starting on `weekStartsOn`. Six rows always, so the grid never changes height. */
export function monthGrid(year: number, month: number, weekStartsOn: Weekday): Date[][] {
const first = startOfWeek(makeDate(year, month, 1), weekStartsOn);
return Array.from({ length: 6 }, (_, week) => Array.from({ length: 7 }, (_, day) => addDays(first, week * 7 + day)));
}
/** `2026-12-03`: the form a date input submits. */
export function toISODate(date: Date | null | undefined): string {
if (!date) return "";
const pad = (n: number, width: number) => String(n).padStart(width, "0");
return `${pad(date.getFullYear(), 4)}-${pad(date.getMonth() + 1, 2)}-${pad(date.getDate(), 2)}`;
}
/** Reads `2026-12-03`. Anything else, or a day the month lacks (`2026-02-30`), is null. */
export function parseISODate(text: string | null | undefined): Date | null {
const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(text ?? "");
if (!match) return null;
const [year, month, day] = [Number(match[1]), Number(match[2]) - 1, Number(match[3])];
if (month > 11 || day < 1 || day > daysInMonth(year, month)) return null;
return makeDate(year, month, day);
}
/** Whether a day falls outside `min` to `max`, or is in the disabled list. */
export function isDayDisabled(date: Date, { min, max, disabledDays }: { min?: Date | null; max?: Date | null; disabledDays?: DisabledDays }): boolean {
if (min && compareDays(date, min) < 0) return true;
if (max && compareDays(date, max) > 0) return true;
if (!disabledDays) return false;
if ("dayOfWeek" in disabledDays) return disabledDays.dayOfWeek.includes(date.getDay());
return disabledDays.some((day) => isSameDay(day, date));
}
/** Where a day stands in a range: its start, its end, inside it, or outside (null). A range of one day is both ends. */
export function rangePosition(date: Date, range: DateRange): { start: boolean; end: boolean; inside: boolean } | null {
const { from, to } = range;
if (!from) return null;
const last = to ?? from;
const [a, b] = compareDays(from, last) <= 0 ? [from, last] : [last, from];
if (compareDays(date, a) < 0 || compareDays(date, b) > 0) return null;
return { start: isSameDay(date, a), end: isSameDay(date, b), inside: true };
}
/** The range after a press on `date`: a first press starts a range, a second ends it (in either order), a third starts again. */
export function nextRange(range: DateRange, date: Date): DateRange {
if (!range.from || range.to) return { from: date, to: null };
return compareDays(date, range.from) < 0 ? { from: date, to: range.from } : { from: range.from, to: date };
}
/** The first day of the week for a locale, from the browser's week data. Monday where the browser has none. */
export function localeWeekStart(locale: string): Weekday {
try {
const info = new Intl.Locale(locale) as Intl.Locale & { getWeekInfo?: () => { firstDay: number }; weekInfo?: { firstDay: number } };
const firstDay = (info.getWeekInfo?.() ?? info.weekInfo)?.firstDay;
if (firstDay) return (firstDay % 7) as Weekday; // 1 is Monday, 7 is Sunday
} catch {
// An unknown locale: fall through to Monday.
}
return 1;
}
// ---------------------------------------------------------------------------------------------------------------
// The calendar.
// ---------------------------------------------------------------------------------------------------------------
type CalendarBase = Omit<ComponentProps<"div">, "defaultValue" | "onChange" | "dir"> & {
/** The month on screen (any day in it), when the parent holds it. Use it with onMonthChange. */
month?: Date;
/** The month shown first. Defaults to the selected day's month, then the month of `today`. */
defaultMonth?: Date;
/** Called with the first day of the month when the visitor moves to another month. */
onMonthChange?: (month: Date) => void;
/** How many months show side by side. They wrap when there is no room. */
numberOfMonths?: number;
/** The earliest day that can be picked. */
min?: Date | null;
/** The latest day that can be picked. */
max?: Date | null;
/** Days that cannot be picked: a list of dates, or `{ dayOfWeek: [0, 6] }`. */
disabledDays?: DisabledDays;
/** The whole calendar is dimmed and cannot be changed. */
disabled?: boolean;
/** Range mode: the longest range, in days, counting both ends. */
maxDays?: number;
/** The first column: 0 is Sunday, 1 Monday. Defaults to the locale's own week. */
weekStartsOn?: Weekday;
/** The language of month and day names, and the default week start. */
locale?: string;
/** Show the days of the next and previous month that fill the first and last week. */
showOutsideDays?: boolean;
/** `dropdown` replaces the month name with a month and a year select, for jumping far. */
captionLayout?: "label" | "dropdown";
/** The day marked as today. Pass it from the server or the parent; the calendar never reads the clock itself. */
today?: Date;
/** Play a click when a day is picked, if the visitor has sound on. */
sound?: boolean;
/** Paint the calendar's own panel surface, border and padding. Set to false when embedded inside a popover. */
surface?: boolean;
};
export type CalendarSingleProps = { mode?: "single"; value?: Date | null; defaultValue?: Date | null; onValueChange?: (value: Date | null) => void };
export type CalendarMultipleProps = { mode: "multiple"; value?: Date[]; defaultValue?: Date[]; onValueChange?: (value: Date[]) => void };
export type CalendarRangeProps = { mode: "range"; value?: DateRange; defaultValue?: DateRange; onValueChange?: (value: DateRange) => void };
export type CalendarProps = CalendarBase & (CalendarSingleProps | CalendarMultipleProps | CalendarRangeProps);
type Selection = Date | null | Date[] | DateRange;
const NAV = "size-7 text-muted-foreground hover:text-foreground dark:text-foreground/75 [&_svg]:rtl:-scale-x-100";
/**
* A month grid for picking one day, several days or a range. It follows the WAI-ARIA grid pattern: one tab stop, and the
* arrow keys move the focus by day and week, Page Up and Page Down by month. It never reads the clock: pass `today`.
*/
export function Calendar(props: CalendarProps) {
const {
mode = "single",
value,
defaultValue,
onValueChange,
month: monthProp,
defaultMonth,
onMonthChange,
numberOfMonths = 1,
min,
max,
disabledDays,
disabled = false,
maxDays,
weekStartsOn,
locale = "en-US",
showOutsideDays = true,
captionLayout = "label",
today,
sound = true,
surface = true,
className,
...rest
} = props;
const id = useId();
const root = useRef<HTMLDivElement>(null);
const moveFocus = useRef(false);
const [ownValue, setOwnValue] = useState<Selection>(() => defaultValue ?? (mode === "multiple" ? [] : mode === "range" ? { from: null, to: null } : null));
const selection: Selection = value !== undefined ? value : ownValue;
const range: DateRange = mode === "range" ? ((selection as DateRange | null) ?? { from: null, to: null }) : { from: null, to: null };
const picked: Date[] = mode === "multiple" ? ((selection as Date[] | null) ?? []) : mode === "single" ? [selection as Date | null].filter((d): d is Date => Boolean(d)) : [range.from, range.to].filter((d): d is Date => Boolean(d));
const [ownMonth, setOwnMonth] = useState(() => startOfMonth(defaultMonth ?? picked[0] ?? today ?? makeDate(2000, 0, 1)));
const first = startOfMonth(monthProp ?? ownMonth);
const last = addMonths(first, numberOfMonths - 1);
const shown = (date: Date) => compareDays(date, first) >= 0 && compareDays(date, endOfMonth(last)) <= 0;
const [ownFocus, setOwnFocus] = useState<Date | null>(null);
const [hovered, setHovered] = useState<Date | null>(null);
const [turn, setTurn] = useState<"next" | "prev" | null>(null);
// The one day that takes the tab stop: the last focused day while it is on screen, else the picked day, today, or the 1st.
const focusDay = [ownFocus, ...picked, today].find((date): date is Date => Boolean(date && shown(date))) ?? first;
const week = weekStartsOn ?? localeWeekStart(locale);
const dayName = new Intl.DateTimeFormat(locale, { weekday: "long", day: "numeric", month: "long", year: "numeric" });
const caption = new Intl.DateTimeFormat(locale, { month: "long", year: "numeric" });
const weekdayShort = new Intl.DateTimeFormat(locale, { weekday: "short" });
const weekdayLong = new Intl.DateTimeFormat(locale, { weekday: "long" });
const monthName = new Intl.DateTimeFormat(locale, { month: "long" });
// While a range is half picked, days further than `maxDays` from its start are out of reach.
const picking = mode === "range" && range.from && !range.to ? range.from : null;
const blocked = (date: Date) =>
disabled || isDayDisabled(date, { min, max, disabledDays }) || Boolean(picking && maxDays && Math.abs(differenceInDays(picking, date)) >= maxDays);
const setMonth = (next: Date) => {
const start = startOfMonth(next);
if (!isSameMonth(start, first)) setTurn(compareDays(start, first) > 0 ? "next" : "prev");
if (monthProp === undefined) setOwnMonth(start);
onMonthChange?.(start);
};
const commit = (next: Selection) => {
if (value === undefined) setOwnValue(next);
(onValueChange as ((value: Selection) => void) | undefined)?.(next);
};
const pick = (date: Date) => {
if (blocked(date)) return;
setOwnFocus(date);
if (!shown(date)) setMonth(date);
if (sound) play("select");
if (mode === "multiple") commit(picked.some((d) => isSameDay(d, date)) ? picked.filter((d) => !isSameDay(d, date)) : [...picked, date]);
else if (mode === "range") commit(nextRange(range, date));
else commit(date);
};
const focusOn = (date: Date) => {
const next = clampDay(date, min, max);
setOwnFocus(next);
moveFocus.current = true;
if (compareDays(next, first) < 0) setMonth(next);
else if (compareDays(next, endOfMonth(last)) > 0) setMonth(addMonths(next, -(numberOfMonths - 1)));
};
useEffect(() => {
if (!moveFocus.current) return;
moveFocus.current = false;
root.current?.querySelector<HTMLElement>(`[data-slot="calendar-day"][data-day="${toISODate(focusDay)}"]:not([data-outside])`)?.focus();
});
const onKeyDown = (event: KeyboardEvent<HTMLButtonElement>, date: Date) => {
const rtl = event.currentTarget.matches(":dir(rtl)") ? -1 : 1;
const moves: Record<string, () => Date> = {
ArrowLeft: () => addDays(date, -rtl),
ArrowRight: () => addDays(date, rtl),
ArrowUp: () => addDays(date, -7),
ArrowDown: () => addDays(date, 7),
PageUp: () => (event.shiftKey ? addMonths(date, -12) : addMonths(date, -1)),
PageDown: () => (event.shiftKey ? addMonths(date, 12) : addMonths(date, 1)),
Home: () => startOfWeek(date, week),
End: () => addDays(startOfWeek(date, week), 6),
};
const move = moves[event.key];
if (!move) return;
event.preventDefault();
const next = move();
focusOn(next);
if (picking) setHovered(next);
};
const canPrev = !min || compareDays(addMonths(first, -1), startOfMonth(min)) >= 0;
const canNext = !max || compareDays(addMonths(last, 1), startOfMonth(max)) <= 0;
const headers = monthGrid(2026, 10, week)[0]; // any week: only the weekday names are read
const years = (() => {
const from = min?.getFullYear() ?? first.getFullYear() - 100;
const to = Math.max(max?.getFullYear() ?? first.getFullYear() + 10, from);
return Array.from({ length: to - from + 1 }, (_, i) => from + i);
})();
const preview: DateRange = picking && hovered ? { from: picking, to: hovered } : { from: null, to: null };
return (
<div
ref={root}
data-slot="calendar"
data-surface={surface ? "panel" : undefined}
data-disabled={disabled || undefined}
className={cn(
"flex w-fit flex-wrap gap-x-6 gap-y-4 text-sm data-disabled:opacity-50",
surface && "rounded-lg border bg-card p-3 text-card-foreground",
className,
)}
onPointerLeave={() => setHovered(null)}
{...rest}
>
{Array.from({ length: numberOfMonths }, (_, index) => {
const month = addMonths(first, index);
const captionId = `${id}-caption-${index}`;
const weeks = monthGrid(month.getFullYear(), month.getMonth(), week);
return (
<div key={index} data-slot="calendar-month" className="grid gap-2">
<div className="flex h-8 items-center justify-between gap-1">
{index === 0 ? (
<IconButton aria-label="Previous month" size="sm" className={NAV} disabled={disabled || !canPrev} onClick={() => setMonth(addMonths(first, -1))}>
<ChevronLeftIcon />
</IconButton>
) : (
<span className="size-7" />
)}
{captionLayout === "dropdown" && index === 0 ? (
<div className="flex min-w-0 flex-1 justify-center gap-1">
<span id={captionId} className="sr-only" aria-live="polite">
{caption.format(month)}
</span>
<NativeSelect
size="sm"
aria-label="Month"
className="w-auto"
disabled={disabled}
value={month.getMonth()}
onChange={(event) => setMonth(clampDay(makeDate(month.getFullYear(), Number(event.target.value), 1), min && startOfMonth(min), max))}
>
{Array.from({ length: 12 }, (_, m) => (
<NativeSelectOption key={m} value={m} disabled={Boolean((min && compareDays(endOfMonth(makeDate(month.getFullYear(), m, 1)), min) < 0) || (max && compareDays(makeDate(month.getFullYear(), m, 1), max) > 0))}>
{monthName.format(makeDate(2000, m, 1))}
</NativeSelectOption>
))}
</NativeSelect>
<NativeSelect
size="sm"
aria-label="Year"
className="w-auto"
disabled={disabled}
value={month.getFullYear()}
onChange={(event) => setMonth(clampDay(makeDate(Number(event.target.value), month.getMonth(), 1), min && startOfMonth(min), max))}
>
{years.map((year) => (
<NativeSelectOption key={year} value={year}>
{year}
</NativeSelectOption>
))}
</NativeSelect>
</div>
) : (
<div id={captionId} aria-live="polite" data-slot="calendar-caption" className="min-w-0 flex-1 truncate text-center font-medium">
{caption.format(month)}
</div>
)}
{index === numberOfMonths - 1 ? (
<IconButton aria-label="Next month" size="sm" className={NAV} disabled={disabled || !canNext} onClick={() => setMonth(addMonths(first, 1))}>
<ChevronRightIcon />
</IconButton>
) : (
<span className="size-7" />
)}
</div>
<table role="grid" aria-labelledby={captionId} aria-multiselectable={mode !== "single" || undefined} className="border-collapse">
<thead>
<tr>
{headers.map((day) => (
<th key={day.getDay()} scope="col" abbr={weekdayLong.format(day)} className="h-7 w-8 p-0 text-xs font-normal text-muted-foreground">
{weekdayShort.format(day)}
</th>
))}
</tr>
</thead>
<tbody
key={toISODate(month)}
className={cn(
"motion-reduce:animate-none",
turn === "next" && "animate-[calendar-from-end_180ms_ease-out] rtl:animate-[calendar-from-start_180ms_ease-out]",
turn === "prev" && "animate-[calendar-from-start_180ms_ease-out] rtl:animate-[calendar-from-end_180ms_ease-out]",
)}
>
{weeks.map((days, w) => (
<tr key={w}>
{days.map((date) => {
const outside = !isSameMonth(date, month);
if (outside && !showOutsideDays) return <td key={date.getDate()} role="presentation" className="p-0" />;
const off = blocked(date);
// Outside days are only fillers: they never show a selection, so two months side by side never show it twice.
const inRange = mode === "range" && !outside ? rangePosition(date, range) : null;
const inPreview = !inRange && !outside && rangePosition(date, preview);
const selected = !outside && (mode === "range" ? Boolean(inRange) : picked.some((d) => isSameDay(d, date)));
const end = mode === "range" ? Boolean(inRange && (inRange.start || inRange.end)) : selected;
const band = inRange ?? inPreview;
return (
<td
key={date.getDate()}
role="gridcell"
aria-selected={selected}
className={cn(
"p-0",
band && (inRange ? "bg-accent" : "bg-accent/50"),
band && band.start && "rounded-s-md",
band && band.end && "rounded-e-md",
)}
>
<button
type="button"
data-slot="calendar-day"
data-day={toISODate(date)}
data-outside={outside || undefined}
data-selected={end || undefined}
data-today={isSameDay(date, today) || undefined}
aria-label={dayName.format(date)}
aria-current={isSameDay(date, today) ? "date" : undefined}
aria-disabled={off || undefined}
tabIndex={!outside && isSameDay(date, focusDay) && !disabled ? 0 : -1}
disabled={disabled}
onClick={() => pick(date)}
onKeyDown={(event) => {
if (event.key === "Enter" || event.key === " ") return; // the button's own press picks it
onKeyDown(event, date);
}}
onFocus={() => {
if (!outside) setOwnFocus(date);
if (picking) setHovered(date);
}}
onPointerEnter={() => picking && setHovered(date)}
className={cn(
"relative grid size-8 cursor-pointer place-items-center rounded-md tabular-nums outline-none select-none",
"transition-[background-color,color] duration-150 ease-out motion-reduce:transition-none",
"hover:bg-accent hover:text-accent-foreground focus-visible:z-10 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring",
"data-outside:text-muted-foreground",
"aria-disabled:cursor-not-allowed aria-disabled:text-muted-foreground aria-disabled:line-through aria-disabled:hover:bg-transparent disabled:cursor-not-allowed",
"data-today:font-semibold data-today:after:absolute data-today:after:bottom-1 data-today:after:size-1 data-today:after:rounded-full data-today:after:bg-current",
band && !end && "text-accent-foreground",
end && "bg-primary text-primary-foreground hover:bg-primary hover:text-primary-foreground",
)}
>
{date.getDate()}
</button>
</td>
);
})}
</tr>
))}
</tbody>
</table>
</div>
);
})}
</div>
);
}Files and dependencies
- Adds
components/ui/calendar.tsx- Packages
- None
- Brings along
- Icon buttonNative selectSound engine
- Icons
chevron-leftchevron-right
Changelog
- 1.0.0 · 2026-12-03First release.