Javascript react datepicker,发出禁用特定日期的命令
我正在使用react datepicker来实现日期和日历,它工作得很好,我已经成功地集成了该组件,但是在禁用默认日期时面临一个问题。我正在使用下面的代码Javascript react datepicker,发出禁用特定日期的命令,javascript,reactjs,react-redux,react-datepicker,Javascript,Reactjs,React Redux,React Datepicker,我正在使用react datepicker来实现日期和日历,它工作得很好,我已经成功地集成了该组件,但是在禁用默认日期时面临一个问题。我正在使用下面的代码 <DatePicker customInput={<ExampleCustomInput />} className="w-dtsr-date-picker" selected={this.state.startDate} //called when the date is clicked onChange={th
<DatePicker customInput={<ExampleCustomInput />} className="w-dtsr-date-picker"
selected={this.state.startDate} //called when the date is clicked
onChange={this.handleChange} //called only when the value is chnaged
monthsShown={2} //number of months to be shown
minDate={this.props.dateProps.minDate} //min days to be shown in the calendar
maxDate={this.props.dateProps.maxDate} //max days to be shown in the calendar
onChangeRaw={this.handleDateChangeRaw} //preventing the user from manually entering the dates or text in the input text box
/>
默认情况下,如果我想禁用2019年4月25日,我无法做到这一点,我看到该组件有一个名为dayClassName的属性,是否有人使用过该属性,我不知道如何传递日期并将css应用到该特定日期
这是我在其中一个例子中发现的-
dayClassName={date => getDate(date) < Math.random() * 31 ? 'random' : undefined}
dayClassName={date=>getDate(date)
它对我不起作用,不知道如何禁用此特定日期(2019年4月25日),有什么帮助吗?您应该能够使用
dayClassName
道具禁用特定日期,并传递您创建的CSS类以禁用用户单击dayClassName
返回一个JS日期,因此您必须将其与要禁用的日期进行比较,然后传递禁用的CSS类名(如果是true
例如:
道具:
dayClassName={date => date.getTime() === new Date('04/25/2019').getTime() ? 'disabled-date' : undefined}
.disabled-date {
pointer-events: none;
}
CSS:
dayClassName={date => date.getTime() === new Date('04/25/2019').getTime() ? 'disabled-date' : undefined}
.disabled-date {
pointer-events: none;
}
您应该能够使用
dayClassName
prop来禁用特定日期,并传递您创建的CSS类以禁用用户单击dayClassName
返回一个JS日期,因此您必须将其与要禁用的日期进行比较,然后传递禁用的CSS类名(如果是true
例如:
道具:
dayClassName={date => date.getTime() === new Date('04/25/2019').getTime() ? 'disabled-date' : undefined}
.disabled-date {
pointer-events: none;
}
CSS:
dayClassName={date => date.getTime() === new Date('04/25/2019').getTime() ? 'disabled-date' : undefined}
.disabled-date {
pointer-events: none;
}
你可以试试这些道具
dayPickerProps={{
disabledDays={[
new Date(2017, 3, 12),
new Date(2017, 3, 2)
]}
}}
或者直接使用道具作为
disabledDays={[
new Date(2017, 3, 12),
new Date(2017, 3, 2)
]}
编辑:很抱歉,将DatePicker误读为DayPicker。
以上内容适用于DayPicker组件
编辑2:
你试过用道具吗
excludeDates={[new Date(), subDays(new Date(), 1)]}
你可以试试这些道具
dayPickerProps={{
disabledDays={[
new Date(2017, 3, 12),
new Date(2017, 3, 2)
]}
}}
或者直接使用道具作为
disabledDays={[
new Date(2017, 3, 12),
new Date(2017, 3, 2)
]}
编辑:很抱歉,将DatePicker误读为DayPicker。
以上内容适用于DayPicker组件
编辑2:
你试过用道具吗
excludeDates={[new Date(), subDays(new Date(), 1)]}
你能在这里发布你使用的日期选择器组件吗?我的答案基于使用附带的
日期选择器组件的项目。你能在这里发布你使用的日期选择器组件吗?我的答案基于使用附带的日期选择器组件的项目。