docs(date-picker): modify datepicker select-in-range demo (#27751)

* feat: modify datepicker select-in-range demo

* fix: lint
This commit is contained in:
LeoYang 2020-11-13 17:05:16 +08:00 committed by GitHub
parent 7f8957eb9a
commit 520407925a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -21,6 +21,8 @@ const { RangePicker } = DatePicker;
const App = () => { const App = () => {
const [dates, setDates] = useState([]); const [dates, setDates] = useState([]);
const [hackValue, setHackValue] = useState();
const [value, setValue] = useState();
const disabledDate = current => { const disabledDate = current => {
if (!dates || dates.length === 0) { if (!dates || dates.length === 0) {
return false; return false;
@ -30,14 +32,22 @@ const App = () => {
return tooEarly || tooLate; return tooEarly || tooLate;
}; };
const onOpenChange = open => {
if (open) {
setHackValue([]);
setDates([]);
} else {
setHackValue(undefined);
}
};
return ( return (
<RangePicker <RangePicker
value={hackValue || value}
disabledDate={disabledDate} disabledDate={disabledDate}
onCalendarChange={value => { onCalendarChange={val => setDates(val)}
const [start, end] = value; onChange={val => setValue(val)}
const [oldStart, oldEnd] = dates; onOpenChange={onOpenChange}
setDates([start || oldStart, end || oldEnd]);
}}
/> />
); );
}; };