0

我有日期选择器组件(DayPickerSingleDateController)。有 ”

超出范围

属性(仅可用 +4(从到今天)天。)

但正因为如此,会发生错误。如果当前月份没有可用日期,则事件仍然显示当前月份 onClick。

现在我尝试添加 initialMonth 属性,我想在其中检查本月是否没有可用的日期,然后 () => moment().add(1, 'month')。

initialVisibleMonth={.... () => moment().add(1, 'month')}
isOutsideRange={(day) => isInclusivelyBeforeDay(day, moment().add(4, 'days'))}

我怎样才能做到这一点?

4

1 回答 1

1

对于我的问题,我得到了以下解决方案。

我像这样声明了 isAvailableDaysInCurrentMonth 变量。

const firstAvailableDay = moment().add(3, 'days') // in my situation, i need "not earlier then 3 days"
const isCurrentMonthExcludeAvailableDate = (moment().month() !== firstAvailableDay.month());

现在我可以在 singleDatePicker 中设置初始月份。因此,如果当前月份没有可用日期,则设置下个月进行显示。

<DayPickerSingleDateController
 ...
 initialVisibleMonth={isCurrentMonthExcludeAvailableDate ? () => moment().add(1, 'month') : null}
>

我自己找到了这个答案,也许有一个更优雅的解决方案,但它仍然可能对某人有用。

于 2018-11-26T23:29:25.263 回答