mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-01 11:39:28 +08:00
docs(date-picker): modify datepicker select-in-range demo (#27751)
* feat: modify datepicker select-in-range demo * fix: lint
This commit is contained in:
parent
7f8957eb9a
commit
520407925a
@ -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]);
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user