Calendar
A grid of days that lets users select a day, several days or a range of days.
A calendar lays out the days of a month in a grid, and users move from month to month with the two buttons above it. Its mode sets what a press on a day selects: one day, several days or a range of days.
Usage
Examples
Multiple Selection
Deliveries, store visits and stock counts rarely fall on consecutive days. With mode set to "multiple", each press on a day adds it to the selection and a second press removes it again, so users collect exactly the days they need.
Range Selection
A promotion or a reporting period runs from one day to another. Once mode is set to "range", users mark the period by its first and its last day, in either order, and every day between them joins the selection.
Month and Year Dropdowns
Dates far from the current month, such as the start of a lease or a stock count in a past year, take many steps with the navigation buttons. Setting captionLayout to "dropdown" lets users pick the month and the year directly, while startMonth and endMonth set the span of months on offer, which otherwise ends with the current year.
Outline Navigation
Planning a season means stepping through many months, and users should find the buttons that change the month at a glance. Through buttonVariant set to "outline", both buttons carry the emphasis of an outline button, so users recognize them as actions in their own right.
Multiple Months
A period that crosses the end of a month is hard to judge one month at a time. With numberOfMonths set to 2, users see both months at once, and each step of the navigation still moves the calendar by a single month.
Week Numbers
Many retailers plan promotions and assortment changes by calendar week. Once showWeekNumber is on, the calendar numbers every week, following the locale or, with ISOWeek, the ISO standard.
Without Outside Days
By default, the days of the neighboring months complete the first and the last week, and users can select them without changing the month. Where only the days of one month count, as in a monthly plan, showOutsideDays set to false removes them, so no day of another month enters the selection by mistake.
Today
The business date of a store can differ from the date on the device, for example after a late closing or in another time zone. Through the today prop, the application sets the day that the calendar marks as today, so users orient themselves by the date that counts for their work.
Controlled Selection
Often the chosen date drives other parts of a screen, such as the delivery slots offered for that day. Together, selected and onSelect hand the selection to the application, which can preset a date, clear it or react to every change.
Controlled Month
A list of open orders can lead users straight to the month of the order they choose. For this purpose, month and onMonthChange let the application hold the month that the calendar shows, while the navigation buttons keep working.
Hidden Navigation
Where the surrounding interface already switches the month, for example with a period selector in the page header, a second navigation would compete with it. In that case, hideNavigation removes the two buttons of the calendar, while users can still change the month with the keyboard.
Hidden Weekdays
Some choices depend on the date alone, such as the expiry date of a product. Here, hideWeekdays leaves out the row of weekday names, so the calendar needs less room.
Hidden Days
Days before a store opens or after a lease ends play no part in its planning. Matched by hidden, such days drop out of view, so users can't select them and keyboard focus passes over them.
Disabled Navigation
Certain schedules cover one month only, such as the dates of a monthly stock count. With disableNavigation, users can't leave that month, neither with the buttons nor with the keyboard.
Disabled Days
A store that stays closed on certain days accepts no deliveries on them. Passed to disabled, a matcher such as a day of the week keeps those days in view but out of reach: users can't select them, and the arrow keys skip them.
Disabled
While an order awaits approval, its delivery date must not change. Set to true, disabled locks every day, and users can still move between months to read the dates.
API Reference
Calendar
| Prop | mode |
|---|---|
| Type | "single" | "multiple" | "range" |
| Default | – |
| Description | Sets what users select: one day, several days or a range of days. Without it, the calendar renders the days as text and users can't select any. |
| Prop | required |
|---|---|
| Type | boolean |
| Default | false |
| Description | Prevents users from clearing the selection. With it, TypeScript requires selected, and onSelect never receives undefined. |
| Prop | selected |
|---|---|
| Type | Date | Date[] | DateRange |
| Default | – |
| Description | Sets the selection: a date in single mode, an array of dates in multiple mode, and an object with from and to in range mode. Pass it together with onSelect to control the selection. Without onSelect, it only sets the selection at first render. |
| Prop | onSelect |
|---|---|
| Type | (selected: Date | Date[] | DateRange | undefined, triggerDate: Date, modifiers: Modifiers, e: MouseEvent | KeyboardEvent) => void |
| Default | – |
| Description | Runs when users press a day to select or clear it. It receives the selection that follows, the day that users pressed and the modifiers of that day. With it, the calendar shows only the selection passed in selected. |
| Prop | min |
|---|---|
| Type | number |
| Default | – |
| Description | Sets the smallest selection in multiple and range mode. In multiple mode, users can't remove a day while only min days are selected. In range mode, a range with fewer than min days between its start and its end starts over at the pressed day. |
| Prop | max |
|---|---|
| Type | number |
| Default | – |
| Description | Sets the largest selection in multiple and range mode. In multiple mode, a press on another day replaces a selection of max days with that day. In range mode, a range with more than max days between its start and its end starts over at the pressed day. |
| Prop | excludeDisabled |
|---|---|
| Type | boolean |
| Default | false |
| Description | Starts the range over at the pressed day when the range would include a disabled day. It applies in range mode. |
| Prop | resetOnSelect |
|---|---|
| Type | boolean |
| Default | false |
| Description | Starts a new range at the pressed day when the range is complete, instead of moving its start or its end. It applies in range mode. |
| Prop | disabled |
|---|---|
| Type | Matcher | Matcher[] |
| Default | – |
| Description | Disables the matching days, so users can't select them. A matcher is true, a date, an array of dates, a range, a function, or an object with before, after or dayOfWeek. true disables every day. |
| Prop | hidden |
|---|---|
| Type | Matcher | Matcher[] |
| Default | – |
| Description | Hides the matching days. Their cells stay in the grid and are empty. |
| Prop | modifiers |
|---|---|
| Type | Record<string, Matcher | Matcher[] | undefined> |
| Default | – |
| Description | Assigns custom modifiers, such as holiday, to the days that match them. modifiersClassNames and modifiersStyles style these days, and the event handlers receive the modifiers of a day. |
| Prop | today |
|---|---|
| Type | Date |
| Default | – |
| Description | Sets the day that the calendar marks as today. Without it, the calendar marks the current date. |
| Prop | autoFocus |
|---|---|
| Type | boolean |
| Default | false |
| Description | Moves focus to a day when the calendar appears: to the selected day, otherwise to today, otherwise to the first day of the month that users can focus. |
| Prop | defaultMonth |
|---|---|
| Type | Date |
| Default | – |
| Description | Sets the month that the calendar shows at first render. The calendar then tracks the month itself. Without it, the calendar opens on the current month. |
| Prop | month |
|---|---|
| Type | Date |
| Default | – |
| Description | Sets the month that the calendar shows and makes the month controlled. Update it in onMonthChange. |
| Prop | onMonthChange |
|---|---|
| Type | (month: Date) => void |
| Default | – |
| Description | Runs when users move to another month. It receives the first day of the first month that the calendar then shows. |
| Prop | startMonth |
|---|---|
| Type | Date |
| Default | – |
| Description | Sets the earliest month that users can move to and hides the days before it. Without it, a calendar with a year dropdown starts 100 years before the current year. |
| Prop | endMonth |
|---|---|
| Type | Date |
| Default | – |
| Description | Sets the latest month that users can move to and hides the days after it. Without it, a calendar with a year dropdown ends with the current year. |
| Prop | numberOfMonths |
|---|---|
| Type | number |
| Default | 1 |
| Description | Sets how many months the calendar shows at the same time. The months stack on narrow screens and sit side by side from the md breakpoint. |
| Prop | pagedNavigation |
|---|---|
| Type | boolean |
| Default | false |
| Description | Moves the calendar by numberOfMonths months per step instead of by one month. |
| Prop | reverseMonths |
|---|---|
| Type | boolean |
| Default | false |
| Description | Shows several months in reverse order, with the latest month first. |
| Prop | disableNavigation |
|---|---|
| Type | boolean |
| Default | false |
| Description | Prevents users from moving to another month. The navigation buttons and the dropdowns stay visible and are disabled. |
| Prop | hideNavigation |
|---|---|
| Type | boolean |
| Default | false |
| Description | Hides the two navigation buttons. Users can still change the month with the keyboard and with the dropdowns. |
| Prop | onNextClick |
|---|---|
| Type | (month: Date) => void |
| Default | – |
| Description | Runs when users press the button for the next month. It receives the month that the calendar moves to. |
| Prop | onPrevClick |
|---|---|
| Type | (month: Date) => void |
| Default | – |
| Description | Runs when users press the button for the previous month. It receives the month that the calendar moves to. |
| Prop | captionLayout |
|---|---|
| Type | "label" | "dropdown" | "dropdown-months" | "dropdown-years" |
| Default | "label" |
| Description | Sets how the caption shows month and year. "label" shows both as text, "dropdown" shows a dropdown for each, and "dropdown-months" and "dropdown-years" show a dropdown for one of them and the other as text. |
| Prop | reverseYears |
|---|---|
| Type | boolean |
| Default | false |
| Description | Lists the years in the year dropdown from the latest to the earliest. |
| Prop | navLayout |
|---|---|
| Type | "around" | "after" |
| Default | – |
| Description | Sets where the navigation buttons sit in the markup. "around" renders the previous button before the caption and the next button after it, and "after" renders both after the caption. Without it, both come before the first month. |
| Prop | buttonVariant |
|---|---|
| Type | "default" | "outline" | "secondary" | "ghost" | "destructive" | "link" |
| Default | "ghost" |
| Description | Sets the Button variant of the two navigation buttons. |
| Prop | showOutsideDays |
|---|---|
| Type | boolean |
| Default | true |
| Description | Shows the days of the previous and the next month in the first and the last week of a month. |
| Prop | showWeekNumber |
|---|---|
| Type | boolean |
| Default | false |
| Description | Adds a column with the number of each week. |
| Prop | fixedWeeks |
|---|---|
| Type | boolean |
| Default | false |
| Description | Shows six weeks for every month, so the calendar keeps its height from month to month. Days of the next month fill the added weeks. |
| Prop | hideWeekdays |
|---|---|
| Type | boolean |
| Default | false |
| Description | Hides the row with the names of the weekdays. |
| Prop | animate |
|---|---|
| Type | boolean |
| Default | false |
| Description | Animates the change between months with the CSS animations that react-day-picker defines for its animation class names. The calendar doesn't load that stylesheet. |
| Prop | footer |
|---|---|
| Type | ReactNode |
| Default | – |
| Description | Adds content below the months as a live region, so screen readers announce it when it changes. The calendar sets no classes for it. |
| Prop | locale |
|---|---|
| Type | Partial<Locale> |
| Default | enUS |
| Description | Sets the language of the month and weekday names and the first day of the week. Pass a locale from react-day-picker/locale. |
| Prop | dir |
|---|---|
| Type | string |
| Default | – |
| Description | Sets the text direction of the calendar. With "rtl", the left and the right arrow key swap their direction. |
| Prop | weekStartsOn |
|---|---|
| Type | 0 | 1 | 2 | 3 | 4 | 5 | 6 |
| Default | – |
| Description | Sets the first day of the week, where 0 is Sunday. Without it, the locale decides. |
| Prop | ISOWeek |
|---|---|
| Type | boolean |
| Default | false |
| Description | Uses ISO week dates instead of the locale. weekStartsOn and firstWeekContainsDate then have no effect. |
| Prop | broadcastCalendar |
|---|---|
| Type | boolean |
| Default | false |
| Description | Lays out the weeks of a month by the broadcast calendar. Weeks then start on Monday, whatever weekStartsOn says. |
| Prop | firstWeekContainsDate |
|---|---|
| Type | 1 | 4 |
| Default | – |
| Description | Sets the day of January that always falls in the first week of the year, which decides the week numbers. Without it, the locale decides. |
| Prop | numerals |
|---|---|
| Type | Numerals |
| Default | "latn" |
| Description | Sets the numbering system of the digits, such as "arab" or "deva". |
| Prop | timeZone |
|---|---|
| Type | string |
| Default | – |
| Description | Sets the time zone of the calendar as an IANA name or a UTC offset. The prop is experimental. |
| Prop | noonSafe |
|---|---|
| Type | boolean |
| Default | false |
| Description | Sets the time of all dates to noon in the time zone, so that historical offsets can't move a date across midnight. It applies when timeZone is set, and it is experimental. |
| Prop | useAdditionalWeekYearTokens |
|---|---|
| Type | boolean |
| Default | false |
| Description | Allows the week year tokens YY and YYYY in the formats that the date library receives. |
| Prop | useAdditionalDayOfYearTokens |
|---|---|
| Type | boolean |
| Default | false |
| Description | Allows the day of year tokens D and DD in the formats that the date library receives. |
| Prop | dateLib |
|---|---|
| Type | Partial<DateLib> |
| Default | – |
| Description | Replaces functions of the date library that the calendar computes and formats dates with. The prop is experimental. |
| Prop | classNames |
|---|---|
| Type | Partial<ClassNames> |
| Default | – |
| Description | Sets the class names of the elements of the calendar by key, such as month_caption or weekday. A key replaces the classes that the calendar sets for that element. |
| Prop | modifiersClassNames |
|---|---|
| Type | Record<string, string> |
| Default | – |
| Description | Sets a class name for the days that match a modifier, by the name of the modifier. For a modifier such as today or selected, it replaces the class that the calendar sets. |
| Prop | styles |
|---|---|
| Type | Partial<Styles> |
| Default | – |
| Description | Sets inline styles for the elements of the calendar, by the same keys as classNames. |
| Prop | modifiersStyles |
|---|---|
| Type | Record<string, CSSProperties> |
| Default | – |
| Description | Sets inline styles for the days that match a modifier, by the name of the modifier. |
| Prop | components |
|---|---|
| Type | Partial<CustomComponents> |
| Default | – |
| Description | Replaces the components that render the elements of the calendar by key, such as DayButton or Chevron. The calendar sets Root, Chevron, DayButton and WeekNumber itself, and a key replaces its component. |
| Prop | formatters |
|---|---|
| Type | Partial<Formatters> |
| Default | – |
| Description | Replaces the functions that format the texts of the calendar, such as formatCaption or formatWeekdayName. The calendar sets formatMonthDropdown to the short name of the month in the language of locale, or of the runtime when locale isn't set, and the key replaces it. |
| Prop | labels |
|---|---|
| Type | Partial<Labels> |
| Default | – |
| Description | Replaces the functions that create the aria-label of the elements, such as labelNext or labelDayButton. |
| Prop | onDayClick |
|---|---|
| Type | (date: Date, modifiers: Modifiers, e: MouseEvent) => void |
| Default | – |
| Description | Runs when users press a day that isn't disabled. With it, the calendar renders the days as buttons even without a mode. |
| Prop | onDayFocus |
|---|---|
| Type | (date: Date, modifiers: Modifiers, e: FocusEvent) => void |
| Default | – |
| Description | Runs when a day receives focus. |
| Prop | onDayBlur |
|---|---|
| Type | (date: Date, modifiers: Modifiers, e: FocusEvent) => void |
| Default | – |
| Description | Runs when a day loses focus. |
| Prop | onDayKeyDown |
|---|---|
| Type | (date: Date, modifiers: Modifiers, e: KeyboardEvent) => void |
| Default | – |
| Description | Runs when users press a key while a day has focus. |
| Prop | onDayMouseEnter |
|---|---|
| Type | (date: Date, modifiers: Modifiers, e: MouseEvent) => void |
| Default | – |
| Description | Runs when the pointer enters a day. |
| Prop | onDayMouseLeave |
|---|---|
| Type | (date: Date, modifiers: Modifiers, e: MouseEvent) => void |
| Default | – |
| Description | Runs when the pointer leaves a day. |
CalendarDayButton
| Prop | day |
|---|---|
| Type | CalendarDay |
| Default | – |
| Description | Sets the day that the button stands for, with its date in day.date. The calendar passes day and modifiers to the component in components.DayButton. The component requires this prop. |
| Prop | modifiers |
|---|---|
| Type | Modifiers |
| Default | – |
| Description | Sets the modifiers of the day as a record of booleans, such as selected, today or range_start. The button takes its selection styles from them and takes focus when focused is true. The component requires this prop. |
| Prop | locale |
|---|---|
| Type | Partial<Locale> |
| Default | – |
| Description | Sets the locale whose code formats the date in the data-day attribute of the button. |