Calendar
A container that displays data in calendar form.
When To Use
When data is in the form of dates, such as schedules, timetables, prices calendar, lunar calendar. This component also supports Year/Month switch.
Examples
- Basic ·
basic - Notice Calendar ·
notice-calendar - Event Range ·
event-range - Card ·
card - Selectable Calendar ·
select - Lunar Calendar ·
lunar - Show Week ·
week - Customize Header ·
customize-header - Custom semantic dom styling ·
style-class
API
Common props ref:Common props
Note: Part of the Calendar's locale is read from value. So, please set the locale of dayjs correctly.
// The default locale is en-US, if you want to use other locale, just set locale in entry file globally.
// import dayjs from 'dayjs';
// import 'dayjs/locale/zh-cn';
// dayjs.locale('zh-cn');
<Calendar cellRender={cellRender} onPanelChange={onPanelChange} onSelect={onSelect} />
| Property | Description | Type | Default | Version | Global Config |
|---|---|---|---|---|---|
| cellRender | Customize cell content | function(current: dayjs, info: { prefixCls: string, originNode: React.ReactElement, today: dayjs, range?: 'start' | 'end', type: PanelMode, locale?: Locale, subType?: 'hour' | 'minute' | 'second' | 'meridiem' }) => React.ReactNode | - | 5.4.0 | × |
| classNames | Customize class for each semantic structure inside the component. Supports object or function. | Record<SemanticDOM, string> | (info: { props })=> Record<SemanticDOM, string> | - | 6.0.0 | |
Customize the display of the date cell, the returned content will override the cell. Please use fullCellRender instead in 5.4.0 and later | function(date: Dayjs): ReactNode | - | < 5.4.0 | × | |
| fullCellRender | Customize cell content | function(current: dayjs, info: { prefixCls: string, originNode: React.ReactElement, today: dayjs, range?: 'start' | 'end', type: PanelMode, locale?: Locale, subType?: 'hour' | 'minute' | 'second' | 'meridiem' }) => React.ReactNode | - | 5.4.0 | × |
| defaultValue | The date selected by default | dayjs | - | × | |
| disabledDate | Function that specifies the dates that cannot be selected, currentDate is same dayjs object as value prop which you shouldn't mutate it (https://github.com/ant-design/ant-design/issues/30987) | (currentDate: Dayjs) => boolean | - | × | |
| fullscreen | Whether to display in full-screen | boolean | true | × | |
| showWeek | Whether to display week number | boolean | false | 5.23.0 | × |
| styles | Customize inline style for each semantic structure inside the component. Supports object or function. | Record<SemanticDOM, CSSProperties> | (info: { props })=> Record<SemanticDOM, CSSProperties> | - | 6.0.0 | |
| headerRender | Render custom header in panel | function(object:{value: Dayjs, type: 'year' | 'month', onChange: f(), onTypeChange: f()}) | - | × | |
| locale | The calendar's locale | object | (default) | × | |
| mode | The display mode of the calendar | month | year | month | × | |
| validRange | To set valid range | [dayjs, dayjs] | - | × | |
| value | The current selected date | dayjs | - | × | |
| onChange | Callback for when date changes | function(date: Dayjs) | - | × | |
| onPanelChange | Callback for when panel changes | function(date: Dayjs, mode: string) | - | × | |
| onSelect | Callback for when a date is selected, include source info | function(date: Dayjs, info: { source: 'year' | 'month' | 'date' | 'customize' }) | - | info: 5.6.0 | × |
Semantic DOM
| Semantic node | Native description | Version |
|---|---|---|
root | Root element containing background, border, border-radius and overall layout structure of the calendar component | 6.0.0 |
header | Header element with layout and style control for year selector, month selector and mode switcher | 6.0.0 |
body | Body element with padding and layout control for the calendar table that contains the calendar grid | 6.0.0 |
content | Content element with width, height and table styling control for the calendar table | 6.0.0 |
item | Item element with background, border, hover state, selected state and other interactive styles for calendar cells | 6.0.0 |
itemContent | Item content element with height, overflow and other style control for custom content area inside calendar cells | 6.4.0 |
Semantic description source: vendor/components/calendar/demo/_semantic.tsx
Design Token
Types, inheritance and declarations retain the pinned native source. Defaults are computed by the native theme and may be overridden by ConfigProvider; this table does not invent static defaults.
| Token | Type | Native description |
|---|---|---|
yearControlWidth | number | string | Width of year select |
monthControlWidth | number | string | Width of month select |
miniContentHeight | number | string | Height of mini calendar content |
fullBg | string | Background color of full calendar |
fullPanelBg | string | Background color of full calendar panel |
itemActiveBg | string | Background color of selected date item |
Declaration source: vendor/components/calendar/style/index.ts
import type { CSSObject } from '@ant-design/cssinjs';
import { unit } from '@ant-design/cssinjs';
import type { PanelComponentToken, PickerPanelToken } from '../../date-picker/style';
import {
genPanelStyle,
initPanelComponentToken,
initPickerPanelToken,
} from '../../date-picker/style';
import { resetComponent } from '../../style';
import type { FullToken, GenerateStyle, GetDefaultToken } from '../../theme/internal';
import { genStyleHooks, mergeToken } from '../../theme/internal';
export interface ComponentToken {
/**
* @desc 年选择器宽度
* @descEN Width of year select
*/
yearControlWidth: number | string;
/**
* @desc 月选择器宽度
* @descEN Width of month select
*/
monthControlWidth: number | string;
/**
* @desc 迷你日历内容高度
* @descEN Height of mini calendar content
*/
miniContentHeight: number | string;
/**
* @desc 完整日历背景色
* @descEN Background color of full calendar
*/
fullBg: string;
/**
* @desc 完整日历面板背景色
* @descEN Background color of full calendar panel
*/
fullPanelBg: string;
/**
* @desc 日期项选中背景色
* @descEN Background color of selected date item
*/
itemActiveBg: string;
}
interface CalendarToken extends FullToken<'Calendar'>, PickerPanelToken, PanelComponentToken {
/**
* @desc 日历类名
* @descEN Calendar class name
*/
calendarCls: string;
/**
* @desc 日期值高度
* @descEN Date value height
*/
dateValueHeight: number | string;
/**
* @desc 周高度
* @descEN Week height
*/
weekHeight: number | string;
/**
* @desc 日期内容高度
* @descEN Date content height
*/
dateContentHeight: number | string;
}
FAQ
How to use Calendar with customize date library?
How to set locale for date-related components?
See How to set locale for date-related components
Date-related components locale is not working?
See FAQ Date-related-components-locale-is-not-working?
How to get date from panel click?
onSelect provide info.source to help on this:
<Calendar
onSelect={(date, { source }) => {
if (source === 'date') {
console.log('Panel Select:', source);
}
}}
/>
Shared native props
Tips: The following generic properties apply to most antd components; those not supported are described separately.
| Property | Description | Type | Default |
|---|---|---|---|
| style | The additional style | CSSProperties | - |
| className | The additional css class | string | - |
| rootClassName | ClassName on the root element | string | - |
| autoFocus | Auto focus when component mounted, only effective for focusable elements like forms, links, etc. | boolean | false |
Install and reproduce an example
npm install antd@6.6.5 @ant-design/icons@6.3.4 dayjs@1.11.23
Use ConfigProvider and native App; configure dayjs locale separately. Each example lists its complete source files and additional pinned dependencies in View code. Example names select demos, not universal component props. See the resource setup guide for theme, locale and SSR.
Native type references
The source viewer includes unchanged native implementations and the following source declarations. Inherited types remain in their native packages. English source comments are preserved as code reference.
vendor/components/calendar/Header.tsxvendor/components/calendar/generateCalendar.tsxvendor/components/calendar/index.tsxvendor/components/calendar/style/index.ts
Source and license
https://github.com/ant-design/ant-design/tree/4a39f54842eade4e565ab336ef6097cd7e723cdd
Original bilingual prose and executable examples are retained. Website-only embeds and token tables are expanded locally. Ant Design is MIT; separately listed dependency notices also apply. Upload previews block outbound requests and do not provide a backend.