syncfusion-react-calendar
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseImplementing Calendar (React)
实现日历组件(React)
Table of Contents
目录
Overview
概述
This skill provides: a short React Quick Start, recommended patterns (single-date, range selection, controlled components), and two reference files: a React-specific getting-started and a concise API reference derived from the Syncfusion React Calendar docs.
Target package: (CalendarComponent)
@syncfusion/ej2-react-calendars本技能资料包含:精简的React快速上手教程、推荐实践(单日期选择、范围选择、受控组件),以及两份参考文件:React专属入门指南和源自Syncfusion React Calendar官方文档的精简API参考。
目标包:(CalendarComponent)
@syncfusion/ej2-react-calendarsQuick Start (React)
快速上手(React)
Install
安装
bash
npm install @syncfusion/ej2-react-calendars @syncfusion/ej2-basebash
npm install @syncfusion/ej2-react-calendars @syncfusion/ej2-baseBasic Example (App.jsx)
基础示例(App.jsx)
jsx
import React, { useState } from 'react';
import { CalendarComponent } from '@syncfusion/ej2-react-calendars';
import '@syncfusion/ej2-base/styles/material3.css';
import '@syncfusion/ej2-calendars/styles/material3.css';
export default function App() {
const [value, setValue] = useState(new Date());
const onChange = (args) => setValue(args.value || args);
return (
<div style={{ padding: 20 }}>
<h3>Select a date</h3>
<CalendarComponent value={value} change={onChange} />
<p>Selected: {value.toDateString()}</p>
</div>
);
}Notes:
- Use the event to sync selected date to React state.
change - Import theme CSS once (global or component-level) to style the control.
jsx
import React, { useState } from 'react';
import { CalendarComponent } from '@syncfusion/ej2-react-calendars';
import '@syncfusion/ej2-base/styles/material3.css';
import '@syncfusion/ej2-calendars/styles/material3.css';
export default function App() {
const [value, setValue] = useState(new Date());
const onChange = (args) => setValue(args.value || args);
return (
<div style={{ padding: 20 }}>
<h3>Select a date</h3>
<CalendarComponent value={value} change={onChange} />
<p>Selected: {value.toDateString()}</p>
</div>
);
}注意事项:
- 使用事件将选中的日期同步到React state中。
change - 全局或组件级别引入一次主题CSS即可为控件添加样式。
Guidance & Patterns
指导与最佳实践
- Controlled component: keep source-of-truth in React state and update via
valueevent.change - Multi-selection: use with
isMultiSelection={true}prop andvalues/addDate()methods.removeDate() - Programmatic navigation: use a to call
ref— both arguments are required (see references/getting-started-react.md).navigateTo(view, date) - Date ranges: for range selection, use DateRangePicker (separate component). The Calendar itself does not have a built-in range highlight mode.
- Accessibility: use wrapper elements with and a separate
role="region"region for announcements — these are not direct Calendar props.aria-live - Week numbers: enable with (the correct prop name).
weekNumber={true}
- 受控组件: 将数据源保存在React state中,通过事件更新
change。value - 多选: 搭配属性和
values/addDate()方法使用removeDate()。isMultiSelection={true} - 程序化导航: 使用调用
ref——两个参数都是必填项(参见参考资料/getting-started-react.md)。navigateTo(view, date) - 日期范围: 如需范围选择,请使用DateRangePicker(独立组件)。Calendar组件本身没有内置的范围高亮模式。
- 无障碍: 使用带的外层元素和独立的
role="region"区域做播报——这些不是Calendar的直接属性。aria-live - 周数: 通过开启(正确的属性名)。
weekNumber={true}
References
参考资料
Navigate to the reference that matches your current task:
跳转到匹配你当前任务的参考资料:
Getting Started
入门指南
📄 Read: references/getting-started-react.md
- Installation and npm setup
- React component examples
- CSS/theme imports
- Using refs and methods
📄 阅读: references/getting-started-react.md
- 安装与npm配置
- React组件示例
- CSS/主题引入
- refs与方法的使用
Date Selection
日期选择
📄 Read: references/date-selection.md
- Single date selection
- Multiple dates and ranges
- Min/max constraints
- Disabling specific dates
📄 阅读: references/date-selection.md
- 单日期选择
- 多日期与范围选择
- 最小/最大日期约束
- 禁用指定日期
Calendar Views
日历视图
📄 Read: references/calendar-views.md
- Month, Year, Decade views
- Navigating between views
- Initial and depth controls
- Programmatic navigation
📄 阅读: references/calendar-views.md
- 月、年、十年视图
- 视图间切换导航
- 初始视图与层级深度控制
- 程序化导航
Styling & Customization
样式与自定义
📄 Read: references/styling-customization.md
- Theme selection and switching
- CSS class customization
- Custom day cell rendering
- RTL and responsive design
📄 阅读: references/styling-customization.md
- 主题选择与切换
- CSS类自定义
- 自定义日期单元格渲染
- RTL与响应式设计
Events & Methods
事件与方法
📄 Read: references/events-methods.md
- Event handlers (change, created, renderDayCell)
- Using refs and imperative methods
- Advanced renderDayCell hook
- Event tracking patterns
📄 阅读: references/events-methods.md
- 事件处理(change、created、renderDayCell)
- refs与命令式方法的使用
- 高级renderDayCell钩子
- 事件跟踪实践
Accessibility & Globalization
无障碍与全球化
📄 Read: references/accessibility-globalization.md
- WCAG 2.1 compliance
- Keyboard navigation
- ARIA attributes
- Locale support and RTL
- Testing for accessibility
📄 阅读: references/accessibility-globalization.md
- WCAG 2.1合规
- 键盘导航
- ARIA属性
- 多语言支持与RTL
- 无障碍测试
API Reference (Quick Lookup)
API参考(快速查询)
📄 Read: references/api-reference.md
- Props, events, methods at a glance
- Common enums and types
- Link to upstream docs
📄 阅读: references/api-reference.md
- 快速查看属性、事件、方法
- 常用枚举与类型
- 官方文档链接
Troubleshooting & Tips
故障排查与技巧
- Styles not applied: confirm CSS imports point to and are loaded before component styles.
node_modules/@syncfusion/ej2-calendars/styles/ - React state mismatch: use the prop and
valueevent to keep React state in sync — do not rely on framework-specific bindings.change - Multiple date selection not working: ensure and use
isMultiSelection={true}(notvalues) for the initial array.value - not working: the method requires two arguments —
navigateTo.navigateTo(view: CalendarView, date: Date) - "Cannot find module": run and confirm
npm install @syncfusion/ej2-react-calendars @syncfusion/ej2-base.package.json - Week numbers not showing: use (not
weekNumber={true}).showWeekNumber
- 样式未生效: 确认CSS引入路径指向,且加载顺序早于组件样式。
node_modules/@syncfusion/ej2-calendars/styles/ - React state不匹配: 使用属性和
value事件保持React state同步——不要依赖框架专属绑定。change - 多日期选择不生效: 确保设置了,且使用
isMultiSelection={true}(而非values)传入初始数组。value - 不生效: 该方法需要两个参数——
navigateTo。navigateTo(view: CalendarView, date: Date) - "找不到模块": 执行,并检查
npm install @syncfusion/ej2-react-calendars @syncfusion/ej2-base配置。package.json - 周数不显示: 使用(而非
weekNumber={true})。showWeekNumber