Calendar
A month calendar for picking a date or a range.
Demo
Usage
import { Calendar, type DateRange } from '@tuttn/slant'
const [range, setRange] = useState<DateRange>({ from: start, to: end })
// Controlled. Click or press Enter to pick a start, then an end; arrows move by day and week, Page Up and Down by month.
<Calendar range value={range} onValueChange={setRange} label="Trip dates" />
// Uncontrolled: the calendar keeps its own selection, and `name` submits it
// with the form as an ISO date ("2026-10-14", or "2026-10-14/2026-10-17" for a range).
<Calendar defaultValue={{ from: due }} name="due" weekStartsOn={0} label="Due date" />
// The month shown is controllable too: onMonthChange gets the first of the month.
<Calendar month={month} onMonthChange={setMonth} value={range} onValueChange={setRange} range />Props
| Prop | Type | Default | Description |
|---|---|---|---|
value | DateRange | — | The selection, controlled. Omit it and the calendar keeps its own, starting from `defaultValue`. |
defaultValue | DateRange | nothing picked | The first selection of an uncontrolled calendar. |
onValueChange | (value: DateRange) => void | — | Called with local-midnight dates whenever a pick changes the selection. |
range | boolean | false | Pick a start and then an end; off, a click picks a single date. |
month | Date | — | The month shown, controlled: any date in it. Omit it and the calendar pages itself, starting from `defaultMonth`. |
defaultMonth | Date | the selection's start, or today | The month an uncontrolled calendar shows first. |
onMonthChange | (month: Date) => void | — | Called with the first of the month whenever the reader pages to another: the head buttons, or the keyboard moving past the month. |
today | Date | now | Which day gets the today ring and `aria-current="date"`. |
label | string | — | The grid's accessible name, read before the month. |
locale | string | 'en' | For the month and weekday names. |
weekStartsOn | 0 | 1 | 1 | 1 for Monday, 0 for Sunday. |
min | Date | — | The earliest day that can be picked. Days before it are dimmed and `aria-disabled`, the arrow and Page keys stop at it, and Previous month disables on its month. |
max | Date | — | The latest day that can be picked. Days after it are dimmed and `aria-disabled`, the arrow and Page keys stop at it, and Next month disables on its month. |
isDateDisabled | (date: Date) => boolean | — | Called with each day's local midnight; days it returns true for are dimmed and `aria-disabled`. The arrow keys still reach them, but they can't be picked. |
name | string | — | Submits the selection with a form: a hidden input holding an ISO date, `2026-10-14`, or `2026-10-14/2026-10-17` for a range (empty while nothing is picked). |
form | string | — | The id of the form the hidden input belongs to, when the calendar sits outside it. |
…rest | HTMLAttributes<HTMLDivElement> | — | className, style and other attributes go on the root; the ref too. |
Under right-to-left text the week runs from the right, the Left and Right arrows swap, and the month chevrons mirror. The month buttons are named by messages.previousMonth and messages.nextMonth, so a <Slant messages> root renames them; month and weekday names follow locale.
min and max limit the days that can be picked, and isDateDisabled rules out any others (weekends, booked days). Those days are dimmed and aria-disabled: a click or Enter on one doesn't pick it. The arrow and Page keys stop at the limits but still reach the disabled days in between, and the month buttons become aria-disabled on the months the limits fall in, keeping their focus. Without a selection, the first focus is today, or the nearest day that can be picked when today can't. For a typed date with this calendar in a popup, see Date picker.