Calendar
A month of days to pick a date or a range, with days that cannot be picked.
| Su | Mo | Tu | We | Th | Fr | Sa |
|---|---|---|---|---|---|---|
Installation
npx @yolkui/cli add calendarA range
mode="range" picks a start and an end: the first click starts the range, the second ends it. The days between sit on a grey band that is cut at the end of each week. numberOfMonths shows months side by side from md, stacked on a phone.
| Su | Mo | Tu | We | Th | Fr | Sa |
|---|---|---|---|---|---|---|
| Su | Mo | Tu | We | Th | Fr | Sa |
|---|---|---|---|---|---|---|
Days that cannot be picked
disabled takes dates and rules: { before: date }, { after: date }, { dayOfWeek: [0, 6] } or a function. Those days fade and cannot be clicked; the arrow keys skip them. startMonth and endMonth stop the arrows at the months you allow.
| Su | Mo | Tu | We | Th | Fr | Sa |
|---|---|---|---|---|---|---|
Days of the months around
By default a month shows only its own days. showOutsideDays fills the first and last rows with the days around it in muted text, and fixedWeeks keeps six rows, so the calendar never changes height between months.
| Su | Mo | Tu | We | Th | Fr | Sa |
|---|---|---|---|---|---|---|
In a card
The calendar has no fill of its own, so it sits on whatever surface holds it. Inside a Card drop its padding with className="p-0".
Delivery day
| Su | Mo | Tu | We | Th | Fr | Sa |
|---|---|---|---|---|---|---|
Date picker
A Button that opens the Calendar in a Popover, under a label. The button is named by the label and its own text together (aria-labelledby with both ids), so a screen reader hears what the date is for and the date. The popover drops its own padding (className="w-auto p-0"; the calendar keeps its 12) and takes an aria-label, since it has no title. Control open and close it in onSelect, so picking a day closes it and focus goes back to the button.
Right to left and other languages
locale (from react-day-picker/locale) writes the month and weekdays in a language and starts the week on its day. In a right-to-left app the Calendar reads Base UI's DirectionProvider: the week runs from the right, the arrows turn round and ArrowLeft moves to the next day.
| س | ح | ن | ث | ر | خ | ج |
|---|---|---|---|---|---|---|
API
Calendar takes every prop of react-day-picker's DayPicker; the ones used most:
| Prop | Type | What it does |
|---|---|---|
mode | single · multiple · range | How days are picked. Without a mode the calendar only shows dates. |
selected · onSelect | Date · Date[] · DateRange | The picked day, days or range, and what to do when it changes. |
disabled | Matcher | Matcher[] | Days that cannot be picked: dates, { before }, { after }, { dayOfWeek } or a function. |
defaultMonth · month · onMonthChange | Date | The month shown first, or the shown month controlled. |
startMonth · endMonth | Date | The first and last month the arrows reach. |
numberOfMonths | number | Months shown side by side (stacked below md). |
showOutsideDays · fixedWeeks | boolean | The days of the months around in muted text (off by default); six rows in every month. |
locale · weekStartsOn | Locale · 0–6 | The language of the month and weekdays, and the first day of the week. |
captionLayout | label · dropdown · dropdown-months · dropdown-years | The month's name, or dropdowns to jump to a month and year (or only one of them); give startMonth and endMonth to set the years listed. |
buttonVariant | Button's variant | The Button variant of the arrows; ghost by default. |
className | string | A day is 32px (--cell-size); [--cell-size:--spacing(9)] makes it 36, the default control height, for a calendar on its own on a touch screen. |
Accessibility
The month is a grid named by its month and year; each day is a button whose name is the full date, with "Today" and "selected" when they apply.
- Tab reaches the arrows and then one day; the arrow keys move between days, Page Up and Page Down by month (with Shift by year), Home and End to the week's ends. Enter or Space picks.
- Changing the month is announced: the month's name is a polite live region.
- An arrow with no month left fades but keeps its place in the Tab order, so focus is never lost.
- Today and the picked day differ by more than colour: today keeps the text colour on a grey fill, the picked day inverts it, and a screen reader hears both. In Windows High Contrast the picked days take the system highlight and today a frame.