mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-04 04:58:55 +08:00
parent
bb3c6700b6
commit
e2c76ff9fb
@ -66,6 +66,7 @@ ReactDOM.render(
|
|||||||
<br />
|
<br />
|
||||||
<DatePicker picker="month" disabledDate={disabledDate} />
|
<DatePicker picker="month" disabledDate={disabledDate} />
|
||||||
<br />
|
<br />
|
||||||
|
<RangePicker disabledDate={disabledDate} />
|
||||||
<RangePicker
|
<RangePicker
|
||||||
disabledDate={disabledDate}
|
disabledDate={disabledDate}
|
||||||
disabledTime={disabledRangeTime}
|
disabledTime={disabledRangeTime}
|
||||||
|
50
components/date-picker/demo/select-in-range.md
Normal file
50
components/date-picker/demo/select-in-range.md
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
---
|
||||||
|
order: 6.1
|
||||||
|
title:
|
||||||
|
zh-CN: 选择不超过七天的范围
|
||||||
|
en-US: Select range dates in 7 days
|
||||||
|
---
|
||||||
|
|
||||||
|
## zh-CN
|
||||||
|
|
||||||
|
这里举例如何用 `onCalendarChange` 和 `disabledDate` 来限制动态的日期区间选择。
|
||||||
|
|
||||||
|
## en-US
|
||||||
|
|
||||||
|
A example shows how to select a dynamic range by using `onCalendarChange` and `disabledDate`.
|
||||||
|
|
||||||
|
```jsx
|
||||||
|
import React, { useState, useCallback } from 'react';
|
||||||
|
import { DatePicker } from 'antd';
|
||||||
|
|
||||||
|
const { RangePicker } = DatePicker;
|
||||||
|
|
||||||
|
const App = () => {
|
||||||
|
const [dates, setDates] = useState([]);
|
||||||
|
|
||||||
|
const disabledDate = current => {
|
||||||
|
if (!dates || dates.length === 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const tooLate = dates[0] && current.diff(dates[0], 'days') > 7;
|
||||||
|
const tooEarly = dates[1] && dates[1].diff(current, 'days') > 7;
|
||||||
|
return tooEarly || tooLate;
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<RangePicker
|
||||||
|
disabledDate={disabledDate}
|
||||||
|
onCalendarChange={dates => {
|
||||||
|
setDates(dates);
|
||||||
|
}}
|
||||||
|
onOpenChange={open => {
|
||||||
|
if (!open) {
|
||||||
|
setDates([]);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
ReactDOM.render(<App />, mountNode);
|
||||||
|
```
|
Loading…
Reference in New Issue
Block a user