mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-01 03:29:39 +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 [dates, setDates] = useState([]);
|
||||
const [hackValue, setHackValue] = useState();
|
||||
const [value, setValue] = useState();
|
||||
const disabledDate = current => {
|
||||
if (!dates || dates.length === 0) {
|
||||
return false;
|
||||
@ -30,14 +32,22 @@ const App = () => {
|
||||
return tooEarly || tooLate;
|
||||
};
|
||||
|
||||
const onOpenChange = open => {
|
||||
if (open) {
|
||||
setHackValue([]);
|
||||
setDates([]);
|
||||
} else {
|
||||
setHackValue(undefined);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<RangePicker
|
||||
value={hackValue || value}
|
||||
disabledDate={disabledDate}
|
||||
onCalendarChange={value => {
|
||||
const [start, end] = value;
|
||||
const [oldStart, oldEnd] = dates;
|
||||
setDates([start || oldStart, end || oldEnd]);
|
||||
}}
|
||||
onCalendarChange={val => setDates(val)}
|
||||
onChange={val => setValue(val)}
|
||||
onOpenChange={onOpenChange}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user