简体   繁体   English

DatePicker 蚂蚁设计 - 禁用当前/今天日期

[英]DatePicker ant design - disable the current/todays date

How do you disable the current/today's date with DatePicker in the Ant Design library?如何在Ant Design库中使用 DatePicker 禁用当前/今天的日期? I need to move the default date back one day (I successfully did this) and disable the current day and all days in the future.我需要将默认日期移回一天(我成功地做到了这一点)并禁用当前日期和未来的所有日期。 I have it really close, except I can't seem to disable the current/today?我真的很接近,除了我似乎无法禁用当前/今天? Can you not do that?你不能这样做吗?

This is what I'm trying?这就是我正在尝试的?

private disabledDate = (current) => {
    return current && current >= moment().endOf('day');
}
....
<DatePicker
    defaultValue={moment().subtract(1, 'day')}
    value={moment(this.state.reportPeriod, dateFormat)}
    format={'MMM D, YYYY'}
    disabledDate={this.disabledDate}
    onChange={this.selectDate}
/>

Ant Designs example page has an example of this on codepen . Ant Designs 示例页面在codepen上有一个示例。 Their function can be found below (assuming you're trying to disable today and days in the past. If you're looking for today and in the future, just use > instead of < .它们的功能可以在下面找到(假设您试图禁用今天和过去的日子。如果您正在寻找今天和未来,只需使用>而不是<

function disabledDate(current) {
  // Can not select days before today and today
  return current && current < moment().endOf('day');
}

Edit: So the function to disable today and all future dates is:编辑:所以禁用今天和所有未来日期的功能是:

function disabledDate(current) {
  return current && current > moment().startOf('day');
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM