Calendar
An easily stylable calendar component.
View as Markdown| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
Anatomy
Import the component and assemble its parts:
import { Calendar } from '@base-ui-components/react/calendar';
<Calendar.Root>
<Calendar.SetPreviousMonth />
<Calendar.SetNextMonth />
<Calendar.SetMonth />
<Calendar.DayGrid>
<Calendar.DayGridHeader>
<Calendar.DayGridHeaderRow>
<Calendar.DayGridHeaderCell />
</Calendar.DayGridHeaderRow>
</Calendar.DayGridHeader>
<Calendar.DayGridBody>
<Calendar.DayGridRow>
<Calendar.DayGridCell>
<Calendar.DayButton />
</Calendar.DayGridCell>
</Calendar.DayGridRow>
</Calendar.DayGridBody>
</Calendar.DayGrid>
</Calendar.Root>API reference
Root
Groups all parts of the calendar.
Renders a <div> element.
defaultValueTemporalValue
—
defaultValueTemporalValue
—- Name
- Description
The uncontrolled value that should be initially selected. To render a controlled (Range)Calendar, use the
valueprop instead.- Type
Date | null | undefined
valueTemporalValue
—
valueTemporalValue
—- Name
- Description
The controlled value that should be selected. To render an uncontrolled (Range)Calendar, use the
defaultValueprop instead.- Type
Date | null | undefined
onValueChangefunction
—
onValueChangefunction
—- Name
- Description
Event handler called when the selected value changes. Provides the new value as an argument. Has
getValidationError()in theeventDetailsto retrieve the validation error associated to the new value.- Type
| (( value: TemporalValue, eventDetails: Calendar.Root.ChangeEventDetails, ) => void) | undefined
defaultVisibleDateDate
—
defaultVisibleDateDate
—- Description
The date used to decide which month should be initially displayed in the Day Grid. To render a controlled Calendar, use the
visibleDateprop instead.- Type
Date | undefined
isDateUnavailable((day: Date) => boolean)
—
isDateUnavailable((day: Date) => boolean)
—- Description
Mark specific dates as unavailable. Those dates will not be selectable but they will still be focusable with the keyboard.
- Type
((day: Date) => boolean) | undefined
maxDateDate
—
maxDateDate
—- Name
- Description
Maximal selectable date.
- Type
Date | undefined
minDateDate
—
minDateDate
—- Name
- Description
Minimal selectable date.
- Type
Date | undefined
monthPageSizenumber
1
monthPageSizenumber
1
- Name
- Description
The amount of months to move by when navigating. This is mostly useful when displaying multiple day grids.
- Type
number | undefined- Default
1
onVisibleDateChangefunction
—
onVisibleDateChangefunction
—- Description
Event handler called when the visible date changes. Provides the new visible date as an argument.
- Type
((visibleDate: Date) => void) | undefined
referenceDateDate
'The closest valid date using the validation props.'
referenceDateDate
'The closest valid date using the validation props.'
- Name
- Description
The date used to generate the new value when both
valueanddefaultValueare empty.- Type
Date | undefined- Default
'The closest valid date using the validation props.'
styleUnion
—
styleUnion
—- Name
- Type
| React.CSSProperties | (( state: Calendar.Root.State, ) => CSSProperties | undefined) | undefined
timezonestring
'The timezone of the "value" or "defaultValue" prop if defined, "default" otherwise.'
timezonestring
'The timezone of the "value" or "defaultValue" prop if defined, "default" otherwise.'
- Name
- Description
Choose which timezone to use for the value. Example: "default", "system", "UTC", "America/New_York". If you pass values from other timezones to some props, they will be converted to this timezone before being used.
- Type
string | undefined- Default
'The timezone of the "value" or "defaultValue" prop if defined, "default" otherwise.'
visibleDateDate
—
visibleDateDate
—- Name
- Description
The date used to decide which month should be displayed in the Day Grid. To render an uncontrolled Calendar, use the
defaultVisibleDateprop instead.- Type
Date | undefined
disabledboolean
false
disabledboolean
false
- Name
- Description
Whether the component should ignore user interaction.
- Type
boolean | undefined- Default
false
readOnlyboolean
false
readOnlyboolean
false
- Name
- Description
Whether the user should be unable to select a date in the calendar.
- Type
boolean | undefined- Default
false
invalidboolean
—
invalidboolean
—- Name
- Description
Whether the calendar is forcefully marked as invalid.
- Type
boolean | undefined
childrenReactNode | ((parameters: CalendarContext) => ReactNode)
—
childrenReactNode | ((parameters: CalendarContext) => ReactNode)
—- Name
- Description
The children of the component. If a function is provided, it will be called with the public context as its parameter.
- Type
| React.ReactNode | ((parameters: CalendarContext) => ReactNode)
classNamestring | function
—
classNamestring | function
—- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | ((state: Calendar.Root.State) => string | undefined)
renderReactElement | function
—
renderReactElement | function
—- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: Calendar.Root.State, ) => ReactElement)
data-disabled
Present when the calendar is disabled.
data-readonly
Present when the calendar is readonly.
data-invalid
Present when the current value is invalid.
data-empty
Present when the current value is empty.
data-navigation-direction
Indicates the direction of the navigation (based on the month navigating to).
DayGrid
Groups all the parts of the calendar's day grid.
Renders a <table> element.
styleUnion
—
styleUnion
—- Name
- Type
| React.CSSProperties | (( state: Calendar.DayGrid.State, ) => CSSProperties | undefined) | undefined
classNamestring | function
—
classNamestring | function
—- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | ((state: Calendar.DayGrid.State) => string | undefined)
renderReactElement | function
—
renderReactElement | function
—- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: Calendar.DayGrid.State, ) => ReactElement)
DayGridHeader
Groups all parts of the calendar's day grid header.
Renders a <thead> element.
styleUnion
—
styleUnion
—- Name
- Type
| React.CSSProperties | (( state: Calendar.DayGridHeader.State, ) => CSSProperties | undefined) | undefined
classNamestring | function
—
classNamestring | function
—- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | (( state: Calendar.DayGridHeader.State, ) => string | undefined)
renderReactElement | function
—
renderReactElement | function
—- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: Calendar.DayGridHeader.State, ) => ReactElement)
DayGridHeaderCell
An individual day header cell in the calendar.
Renders a <th> element.
value*Date
—
value*Date
—- Name
- Type
Date
formatter((date: Date) => string)
(date) => adapter.format(date, 'weekday3Letters').charAt(0).toUpperCase()
formatter((date: Date) => string)
(date) => adapter.format(date, 'weekday3Letters').charAt(0).toUpperCase()
- Name
- Description
The formatter function used to display the day of the week.
- Type
((date: Date) => string) | undefined- Default
(date) => adapter.format(date, 'weekday3Letters').charAt(0).toUpperCase()
styleUnion
—
styleUnion
—- Name
- Type
| React.CSSProperties | (( state: Calendar.DayGridHeaderCell.State, ) => CSSProperties | undefined) | undefined
classNamestring | function
—
classNamestring | function
—- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | (( state: Calendar.DayGridHeaderCell.State, ) => string | undefined)
renderReactElement | function
—
renderReactElement | function
—- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: Calendar.DayGridHeaderCell.State, ) => ReactElement)
DayGridBody
Groups all parts of the calendar's day grid.
Renders a <tbody> element.
fixedWeekNumbernumber
—
fixedWeekNumbernumber
—- Name
- Description
Will render the requested amount of weeks by adding weeks of the next month if needed. Set it to 6 to create a Gregorian calendar where all months have the same amount of weeks.
- Type
number | undefined
offsetnumber
0
offsetnumber
0
- Name
- Description
The offset to apply to the rendered month compared to the current month. This is mostly useful when displaying multiple day grids.
- Type
number | undefined- Default
0
styleUnion
—
styleUnion
—- Name
- Type
| React.CSSProperties | (( state: Calendar.DayGridBody.State, ) => CSSProperties | undefined) | undefined
childrenReactNode | ((week: Date, index: number, weeks: Date[]) => ReactNode)
—
childrenReactNode | ((week: Date, index: number, weeks: Date[]) => ReactNode)
—- Name
- Description
The children of the component. If a function is provided, it will be called for each week to render as its parameter.
- Type
| React.ReactNode | (( week: Date, index: number, weeks: Date[], ) => ReactNode)
classNamestring | function
—
classNamestring | function
—- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | (( state: Calendar.DayGridBody.State, ) => string | undefined)
renderReactElement | function
—
renderReactElement | function
—- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: Calendar.DayGridBody.State, ) => ReactElement)
DayGridRow
Groups all cells of a given calendar's day grid row.
Renders a <tr> element.
value*Date
—
value*Date
—- Name
- Description
The date object representing the week.
- Type
Date
styleUnion
—
styleUnion
—- Name
- Type
| React.CSSProperties | (( state: Calendar.DayGridRow.State, ) => CSSProperties | undefined) | undefined
childrenReactNode | ((day: Date, index: number, days: Date[]) => ReactNode)
—
childrenReactNode | ((day: Date, index: number, days: Date[]) => ReactNode)
—- Name
- Description
The children of the component. If a function is provided, it will be called for each day of the week as its parameter.
- Type
| React.ReactNode | ((day: Date, index: number, days: Date[]) => ReactNode)
classNamestring | function
—
classNamestring | function
—- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | (( state: Calendar.DayGridRow.State, ) => string | undefined)
renderReactElement | function
—
renderReactElement | function
—- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: Calendar.DayGridRow.State, ) => ReactElement)
DayGridCell
An individual day cell in the calendar.
Renders a <td> element.
value*Date
—
value*Date
—- Name
- Description
The value to select when this cell is clicked.
- Type
Date
styleUnion
—
styleUnion
—- Name
- Type
| React.CSSProperties | (( state: Calendar.DayGridCell.State, ) => CSSProperties | undefined) | undefined
classNamestring | function
—
classNamestring | function
—- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | (( state: Calendar.DayGridCell.State, ) => string | undefined)
renderReactElement | function
—
renderReactElement | function
—- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: Calendar.DayGridCell.State, ) => ReactElement)
DayButton
An individual interactive day button in the calendar.
Renders a <button> element.
nativeButtonboolean
true
nativeButtonboolean
true
- Name
- Description
Whether the component renders a native
<button>element when replacing it via therenderprop. Set tofalseif the rendered element is not a button (e.g.<div>).- Type
boolean | undefined- Default
true
styleUnion
—
styleUnion
—- Name
- Type
| React.CSSProperties | (( state: Calendar.DayButton.State, ) => CSSProperties | undefined) | undefined
formatstring
adapter.formats.dayOfMonth
formatstring
adapter.formats.dayOfMonth
- Name
- Description
The format used to display the day.
- Type
string | undefined- Default
adapter.formats.dayOfMonth
classNamestring | function
—
classNamestring | function
—- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | (( state: Calendar.DayButton.State, ) => string | undefined)
renderReactElement | function
—
renderReactElement | function
—- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: Calendar.DayButton.State, ) => ReactElement)
data-selected
Present when the day is selected.
data-disabled
Present when the day is disabled.
data-current
Present when the day is the current date.
data-outside-month
Present when the day is outside the month rendered by the day grid wrapping it.
data-unavailable
Present when the day is unavailable.
SetMonth
Displays an element to navigate to a given month in the calendar.
Renders a <button> element.
nativeButtonboolean
true
nativeButtonboolean
true
- Name
- Description
Whether the component renders a native
<button>element when replacing it via therenderprop. Set tofalseif the rendered element is not a button (e.g.<div>).- Type
boolean | undefined- Default
true
styleUnion
—
styleUnion
—- Name
- Type
| React.CSSProperties | (( state: Calendar.SetMonth.State, ) => CSSProperties | undefined) | undefined
target*Date
—
target*Date
—- Name
- Description
The month to navigate to.
- Type
Date
classNamestring | function
—
classNamestring | function
—- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | ((state: Calendar.SetMonth.State) => string | undefined)
renderReactElement | function
—
renderReactElement | function
—- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: Calendar.SetMonth.State, ) => ReactElement)
data-disabled
Present when the button is disabled.
SetPreviousMonth
Displays an element to navigate to the previous month in the calendar.
Renders a <button> element.
nativeButtonboolean
true
nativeButtonboolean
true
- Name
- Description
Whether the component renders a native
<button>element when replacing it via therenderprop. Set tofalseif the rendered element is not a button (e.g.<div>).- Type
boolean | undefined- Default
true
styleUnion
—
styleUnion
—- Name
- Type
| React.CSSProperties | (( state: Calendar.SetPreviousMonth.State, ) => CSSProperties | undefined) | undefined
classNamestring | function
—
classNamestring | function
—- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | (( state: Calendar.SetPreviousMonth.State, ) => string | undefined)
renderReactElement | function
—
renderReactElement | function
—- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: Calendar.SetPreviousMonth.State, ) => ReactElement)
data-disabled
Present when the button is disabled.
SetNextMonth
Displays an element to navigate to the next month in the calendar.
Renders a <button> element.
nativeButtonboolean
true
nativeButtonboolean
true
- Name
- Description
Whether the component renders a native
<button>element when replacing it via therenderprop. Set tofalseif the rendered element is not a button (e.g.<div>).- Type
boolean | undefined- Default
true
styleUnion
—
styleUnion
—- Name
- Type
| React.CSSProperties | (( state: Calendar.SetNextMonth.State, ) => CSSProperties | undefined) | undefined
classNamestring | function
—
classNamestring | function
—- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | (( state: Calendar.SetNextMonth.State, ) => string | undefined)
renderReactElement | function
—
renderReactElement | function
—- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: Calendar.SetNextMonth.State, ) => ReactElement)
data-disabled
Present when the button is disabled.
Viewport
A viewport for displaying calendar month transitions.
This component is only required if you want to animate certain part of a calendar when navigating between months.
The first rendered child element has to handle a ref.
Passes data-current to the currently visible content and data-previous to the previous content when animating between two.
Doesn't render its own HTML element.
children*React.JSX.Element
—
children*React.JSX.Element
—- Name
- Description
The content to render inside the transition container.
- Type
React.JSX.Element
data-current
Applied to the direct child of the viewport when no transitions are present or the new content when it's entering.
data-navigation-direction
Indicates the direction of the navigation (based on the month navigating to).
data-previous
Applied to the direct child of the viewport that contains the exiting content when transitions are present.
data-starting-style
Present when the day grid body is animating in.
data-ending-style
Present when the day grid body is animating out.
Examples
Validation
You can use the minDate and maxDate props to limit the range of selectable dates.
| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
Display week numbers
You can use useWeekList() and useDayList() hooks to build a calendar with additional DOM elements, like week numbers.
| # | S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|---|
| 44 | |||||||
| 45 | |||||||
| 46 | |||||||
| 47 | |||||||
| 48 | |||||||
| 49 |
Timezone support
You can use the timezone prop to display data in the calendar in your preferred timezone.
Timezone support is based on @date-fns/tz.
Calendar is displayed in America/New_York timezone.
| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
Stored date: Thu Apr 17 2025 04:45:00 GMT+0200 (Central European Summer Time)
Animating month changes
You can use the <Calendar.Viewport> component to animate month transitions.
Wrapping the <Calendar.DayGridBody> in the <Calendar.Viewport> renders the previous month if a transition is in progress.
| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
Animating with motion/react
You can use external animation libraries like Framer Motion to animate month transitions.
| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|