Calendar
A month grid for picking one day, several days or a range, used inside the date pickers and available on its own.
Select a day to mark it. Use the arrows to change the month.
When to use
- To show a month that is always visible on the page, such as a deadline calendar next to a form.
- To select a range of days directly, with no field in front of it.
- To build a new picker with its own trigger and footer.
When not to use
- A date field in a form. Use the simple date picker or the date and time picker, which already add the trigger, popover and formatting.
- A period filter. Use the date range picker.
- Typing a known date. Use the date input.
Selection modes
mode sets how days are chosen. selected and onSelect change type with it.
| Mode | selected |
Use for |
|---|---|---|
single |
Date | undefined |
One day, such as a deadline. |
multiple |
Date[] | undefined |
Several separate days, such as hearings. |
range |
DateRange |
A start and an end, with the days between. |
Range
Multiple days
Examples
Month and year dropdowns
captionLayout="dropdown" replaces the title with a month select and a year
select. The years run from 100 years back to 10 years ahead unless you pass
startMonth and endMonth.
Disabled days
disabled takes react-day-picker matchers: a date, a list, { before },
{ after } or { dayOfWeek }. Disabled days cannot be selected.
Content
- Pass
locale. The default is English (enUS), so Portuguese products must passptBRfromdate-fns/locale. - Pass
defaultMonth(or a controlledmonth) when the first month should be predictable. Without it the calendar opens on the current month. - Explain disabled days next to the calendar, for example “Fins de semana e feriados não estão disponíveis”.
Accessibility
- Built on
react-day-pickerv9. The grid has thegridrole, days are buttons, and the selected state is announced. - Arrow keys move between days,
HomeandEndgo to the start and end of the week,PageUpandPageDownchange the month,EnterorSpaceselect a day. - Disabled days are not selectable and set
aria-disabled. - The previous and next buttons have accessible names from the
locale. - The month and year dropdowns are native selects overlaid on the label, so they keep native keyboard and screen reader behavior.
- A calendar shown on the page needs a visible title or a label that names its purpose, for example “Prazo fatal”.
Code
import { Calendar } from "@repo/ui/calendar";
import { ptBR } from "date-fns/locale";
const [day, setDay] = useState<Date | undefined>();
<Calendar locale={ptBR} mode="single" onSelect={setDay} selected={day} />;
Props
Calendar| Prop | Type | Default | Description |
|---|---|---|---|
buttonVariant | "ghost" | "secondary" | "tertiary" | ghost | Button variant of the previous and next month buttons |
captionLayout | "label" | "dropdown" | "dropdown-months" | "dropdown-years" | label | Month caption: plain label or month and year dropdowns |
mode | "single" | "multiple" | "range" | — | Selection mode: one day, several days or a range |
numberOfMonths | number | 1 | Number of months shown side by side |
showOutsideDays | boolean | true | Shows days from the previous and next month |
showWeekNumber | boolean | false | Shows the week number column |
weekStartsOn | "0" | "1" | "2" | "3" | "4" | "5" | "6" | — | First day of the week, from 0 (Sunday) to 6 (Saturday) |
More props| Prop | Type | Default | Description |
|---|---|---|---|
selected, onSelect | depends on mode | — | Selected value and its change handler. Their types follow `mode`. |
defaultMonth, month, onMonthChange | Date, Date, (month: Date) => void | — | First month shown, or a controlled month. |
locale | Locale | enUS | date-fns locale for month, weekday and label texts. |
disabled | Matcher | Matcher[] | — | Days that cannot be selected. |
startMonth, endMonth | Date | — | First and last month the user can reach. With dropdowns the defaults are 100 years back and 10 years ahead. |
formatters, components, classNames | react-day-picker props | — | Customization of the grid. `components` and `classNames` are merged with the defaults. |
className | string | — | Extra classes for the root, for layout only. |
The component also accepts every other DayPicker prop, such as min, max,
modifiers and fixedWeeks. See the
react-day-picker documentation.
Known issues
| Issue | Effect |
|---|---|
locale defaults to enUS. |
A calendar without locale shows English month and weekday names in a Portuguese product. |
Disabled days use opacity-50, and the secondary text of day buttons uses [&>span]:opacity-70. |
Opacity lowers contrast instead of using disabled tokens. |
The focus ring of the focused day is ring-focus/50 and the dropdown focus ring is ring-focus/50. |
A translucent ring is harder to see, mainly on the Dark and Darker themes. |
The dropdown range is computed from new Date() at render time. |
The year list shifts on January 1, so the same code lists different years in different years. |
The DateTimePicker does not use this component. It has its own calendar in date-picker/calendar.tsx. |
Calendars in the date and time picker and in the simple date picker look and behave differently. |