Skip to content

Commit

Permalink
DatePicker组件增加一个defaultDate属性,指定默认的选中时间 (ant-design#593)
Browse files Browse the repository at this point in the history
* 不满一行时,填充的item样式问题

* update test snapshots

* 开放一个defaultDate属性

* 更新DatePicker文档和PropsType

* update demo
  • Loading branch information
M45ter authored and BANG88 committed Aug 2, 2019
1 parent 9b3fd7d commit 54b34b6
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions components/date-picker/PropsType.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import AntDatePickerProps from './datepicker/DatePickerProps';
export interface DatePickerPropsType extends AntDatePickerProps {
value?: Date;
defaultDate?: Date;
mode?: 'datetime' | 'date' | 'year' | 'month' | 'time';
minDate?: Date;
maxDate?: Date;
Expand Down
6 changes: 3 additions & 3 deletions components/date-picker/datepicker/DatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,20 +154,20 @@ class DatePicker extends React.Component<DatePickerProps, any> {

getDefaultMinDate() {
if (!this.defaultMinDate) {
this.defaultMinDate = new Date(2000, 1, 1, 0, 0, 0);
this.defaultMinDate = new Date(2000, 0, 1, 0, 0, 0);
}
return this.defaultMinDate;
}

getDefaultMaxDate() {
if (!this.defaultMaxDate) {
this.defaultMaxDate = new Date(2030, 1, 1, 23, 59, 59);
this.defaultMaxDate = new Date(2030, 0, 1, 23, 59, 59);
}
return this.defaultMaxDate;
}

getDate() {
return this.clipDate(this.state.date || this.getDefaultMinDate());
return this.clipDate(this.state.date || this.props.defaultDate || this.getDefaultMinDate());
}

// used by rmc-picker/lib/PopupMixin.js
Expand Down
1 change: 1 addition & 0 deletions components/date-picker/demo/basic.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export default class PopupExample extends React.Component {
<DatePicker
value={this.state.value}
mode="date"
defaultDate={new Date()}
minDate={new Date(2015, 7, 6)}
maxDate={new Date(2026, 11, 3)}
onChange={this.onChange}
Expand Down
1 change: 1 addition & 0 deletions components/date-picker/demo/basic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default class PopupExample extends React.Component<any, any> {
<DatePicker
value={this.state.value}
mode="date"
defaultDate={new Date()}
minDate={new Date(2015, 7, 6)}
maxDate={new Date(2026, 11, 3)}
onChange={this.onChange}
Expand Down
1 change: 1 addition & 0 deletions components/date-picker/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Properties | Descrition | Type | Default
-----------|------------|------|--------
| mode | mode value, can be a `date` or `time` or `datetime` or `year` or `month` | String | `date` |
| value | the currently selected value | Date | - |
| defaultDate | the default selected value | Date | - |
| minDate | minimum date | Date | 2000-1-1 |
| maxDate | maximum date | Date | 2030-1-1 |
| minuteStep | The amount of time, in minutes, between each minute item. | Number | 1 |
Expand Down
5 changes: 3 additions & 2 deletions components/date-picker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default class DatePicker extends React.Component<DatePickerProps> {
antLocale: PropTypes.object,
};
render() {
const { children, value, itemStyle, ...restProps } = this.props;
const { children, value, defaultDate, itemStyle, ...restProps } = this.props;
const locale = getComponentLocale(
this.props,
(this as any).context,
Expand All @@ -41,7 +41,8 @@ export default class DatePicker extends React.Component<DatePickerProps> {
mode={this.props.mode}
minDate={this.props.minDate}
maxDate={this.props.maxDate}
defaultDate={value}
defaultDate={defaultDate}
date={value}
onValueChange={this.props.onValueChange}
itemStyle={itemStyle}
/>
Expand Down
1 change: 1 addition & 0 deletions components/date-picker/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ subtitle: 日期选择
----|-----|------|------
| mode | 日期选择的类型, 可以是日期`date`,时间`time`,日期+时间`datetime`,年`year`,月`month` | String | `date` |
| value | 当前选中时间 | Date ||
| defaultDate | 默认选中时间 | Date ||
| minDate | 最小可选日期 | Date | 2000-1-1 |
| maxDate | 最大可选日期 | Date | 2030-1-1 |
| minuteStep | 分钟数递增步长设置 | Number | 1 |
Expand Down

0 comments on commit 54b34b6

Please sign in to comment.