javascript - react-dates DayPickerRangeController,如果用户在选择时单击它,是否有办法清除 startDate 或 endDate?
问题描述
我正在尝试找到一种方法让用户在单击已选择的日期时取消选择当前选定的日期。我正在DayPickerRangeController
从react-dates
图书馆使用。
这是我的源代码:
constructor(props) {
super(props);
this.state = {
startDate: null,
endDate: null,
focusedInput: 'startDate'
}
}
handleDateChange = ({ startDate, endDate }) => {
this.setState({ startDate, endDate });
}
handleFocusChange = focusedInput => {
this.setState({ focusedInput: focusedInput || 'startDate' })
}
dayClick = date => {
console.log(date)
}
render() {
return (
<DayPickerRangeController
onDatesChange={this.handleDateChange}
focusedInput={this.state.focusedInput}
onFocusChange={this.handleFocusChange}
startDate={this.state.startDate}
endDate={this.state.endDate}
/>
)
}
解决方案
如果我清楚地理解您的问题,您必须将minimumNights={1}
属性设置为不允许用户选择所选日期。
<DayPickerRangeController
onDatesChange={this.handleDateChange}
focusedInput={this.state.focusedInput}
onFocusChange={this.handleFocusChange}
startDate={this.state.startDate}
endDate={this.state.endDate}
minimumNights={1}
/>
推荐阅读
- php - How to use $_GET in mysqli/php to extract an integer from the URL?
- python - How to find the dominant color in images using Python?
- streamsets - 无法在 mac 中安装 Streamsets
- php - 使用 codeigniter 在 mysql 中插入多行:它只插入一行,并且在这一行中只存储一个第一个字符
- twitter-bootstrap - 单击按钮将显示新的引导程序表单
- assembly - beetwen dw 和 db 与 dup 在装配中有什么区别
- itext - iText 与 Adobe livecycle 的优缺点
- sparql - 如何根据 RDF 中的条件选择属性
- jquery - 带有动画到源位置的 Jquery 模态窗口
- javascript - 如何将字符串转换为对象或数组格式