const [dates, setDates]:any = useState();
const [hackValue, setHackValue]:any = useState();
const [value, setValue]:any = useState([
moment(moment(new Date()).subtract("days", 7).format("YYYY-MM-DD")),
moment(moment(new Date()).format(dateFormat)),
]);
const disabledDate = (current:any) => {
if (!dates || dates.length === 0) {
return false;
}
const tooLate:any = dates[0] && current.diff(dates[0], 'days') > 365;
const tooEarly:any = dates[1] && dates[1].diff(current, 'days') > 365;
return tooEarly || tooLate;
};
const onOpenChange = (open:any) => {
if (open) {
setHackValue([]);
setDates([]);
} else {
setHackValue(undefined);
}
};
<RangePicker
allowClear={false}
style={{ width: "100%" }}
{...props}
value={hackValue || value}
disabledDate={disabledDate}
onCalendarChange={(val:any) => setDates(val)}
onChange={
(val:any) => {
setValue(val);
onChange(val)
}}
onOpenChange={onOpenChange}
format={dateFormat}
/>
RangePicker组件设置时间范围只能选择一年
于 2021-06-29 11:16:09 首次发布