[英]Antd calendar change month on day cell click
If you work with Calendar component from 'antd', then you mentioned that when you click the day of previous/next month, it will change the month automatically.如果您使用 'antd' 的 Calendar 组件,那么您提到当您单击上个月/下个月的日期时,它会自动更改月份。
How to prevent this behaviour?如何防止这种行为? https://ant.design/components/calendar/#header
https://ant.design/components/calendar/#header
1. Disable dates 1. 禁用日期
You can disable dates that not in current month.您可以禁用不在当前月份的日期。 This should prevent clicking on them.
这应该可以防止点击它们。
<Calendar value={selectedDate} disabledDate={disabledDate} />
disabledDate = currentDate => {
return currentDate.isSame(this.selectedDate, 'month'))
};
2. Prevent selecting 2. 防止选择
In case you want more control.如果你想要更多的控制。 You can set value manually with
onSelect
checking if current selected date is in current month.您可以使用
onSelect
检查当前选择的日期是否在当月手动设置值。
<Calendar value={selectedDate} onSelect={this.onSelect} />
onSelect = date => {
if (date.isSame(this.selectedDate, 'month')) {
this.setState({
selectedDate: date,
});
}
};
Note笔记
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.