我正在使用react-day-picker
并且正在正确重置选定的日期,但不确定如何清除 DayPickerInput 占位符。
示例:我选择一个日期范围并单击重置。结果会发生变化,但旧日期仍会出现在输入中。有任何想法吗?
代码:
<div className={isOpen ? 'date-picker block' : 'date-picker'}>
<div className="calendar-picker">
<div className="InputFromTo">
<span className="fal fa-icon fa-calendar-times calendar-picker-icon" aria-hidden="true" title="decorative calendar icon"></span>
<DayPickerInput
value={from}
placeholder="Start Date"
disabled
format="ll"
formatDate={formatDate}
parseDate={parseDate}
dayPickerProps={{
selectedDays: [from, { from, to }],
disabledDays: { after: to },
toMonth: to,
modifiers,
numberOfMonths: 2,
onDayClick: () => filterState.to.getInput().focus(),
}}
onDayChange={handleDayClick}
inputProps={
{readOnly: true }
}
/>
<span className="InputFromTo-to">
<span className="fal fa-icon fa-calendar-times calendar-picker-icon" aria-hidden="true" title="decorative calendar icon"></span>
<DayPickerInput
ref={el => (filterState.to = el)}
value={to}
placeholder="End Date"
disabled
format="ll"
formatDate={formatDate}
parseDate={parseDate}
dayPickerProps={{
selectedDays: [from, { from, to }],
disabledDays: { before: from },
modifiers,
month: from,
fromMonth: from,
numberOfMonths: 2,
}}
onDayChange={handleDayClick}
inputProps={
{readOnly: true }
}
/>
</span>
</div>
</div>
</div>
功能:
function handleResetClick() {
setState({
from: undefined,
to: undefined,
});
}
按钮:
// Custom Clear Refinements Button - clears filters and day picker
const ClearRefinements = ({ items, refine }) => (
<button className="mt-3 clear-button" onClick={() => {refine(items); handleResetClick()}}>
Clear all filters
</button>
);
const CustomClearRefinements = connectCurrentRefinements(ClearRefinements);