From d7e2852915070165227c77d3b0d522204c6f4143 Mon Sep 17 00:00:00 2001 From: liaoxuezhi Date: Wed, 18 Dec 2019 20:08:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E7=90=86=20closeOnSelect=20=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/DatePicker.tsx | 20 ++++++++++++++------ src/components/DateRangePicker.tsx | 4 ++-- src/renderers/Form/DateRange.tsx | 10 ++++++---- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/components/DatePicker.tsx b/src/components/DatePicker.tsx index f4cbbf3f3..b340de2e8 100644 --- a/src/components/DatePicker.tsx +++ b/src/components/DatePicker.tsx @@ -229,9 +229,13 @@ export interface DatePickerState { } export class DatePicker extends React.Component { - static defaultProps: Pick = { + static defaultProps: Pick< + DateProps, + 'viewMode' | 'shortcuts' | 'closeOnSelect' + > = { viewMode: 'days', - shortcuts: '' + shortcuts: '', + closeOnSelect: true }; state: DatePickerState = { isOpened: false, @@ -342,7 +346,8 @@ export class DatePicker extends React.Component { minTime, maxTime, dateFormat, - timeFormat + timeFormat, + closeOnSelect } = this.props; if (!moment.isMoment(value)) { @@ -357,15 +362,17 @@ export class DatePicker extends React.Component { onChange(value.format(format)); - if (dateFormat && !timeFormat) { + if (closeOnSelect && dateFormat && !timeFormat) { this.close(); } } selectRannge(item: any) { + const {closeOnSelect} = this.props; const now = moment(); this.handleChange(item.date(now)); - this.close(); + + closeOnSelect && this.close(); } checkIsValidDate(currentDate: moment.Moment) { @@ -465,7 +472,8 @@ export class DatePicker extends React.Component { popOverContainer, clearable, shortcuts, - utc + utc, + closeOnSelect } = this.props; const isOpened = this.state.isOpened; diff --git a/src/components/DateRangePicker.tsx b/src/components/DateRangePicker.tsx index 0b2ef0403..3c19eec49 100644 --- a/src/components/DateRangePicker.tsx +++ b/src/components/DateRangePicker.tsx @@ -172,7 +172,7 @@ export class DateRangePicker extends React.Component< ranges: 'yesterday,7daysago,prevweek,thismonth,prevmonth,prevquarter', iconClassName: 'fa fa-calendar', resetValue: '', - closeOnSelect: false + closeOnSelect: true }; innerDom: any; @@ -389,7 +389,7 @@ export class DateRangePicker extends React.Component< startDate: range.startDate(now.clone()), endDate: range.endDate(now.clone()) }, - closeOnSelect ? this.close : noop + closeOnSelect ? this.confirm : noop ); } diff --git a/src/renderers/Form/DateRange.tsx b/src/renderers/Form/DateRange.tsx index 3a7279449..08d18b25f 100644 --- a/src/renderers/Form/DateRange.tsx +++ b/src/renderers/Form/DateRange.tsx @@ -4,11 +4,13 @@ import cx from 'classnames'; import {filterDate} from '../../utils/tpl-builtin'; import moment from 'moment'; import 'moment/locale/zh-cn'; -import DateRangePicker from '../../components/DateRangePicker'; +import DateRangePicker, { + DateRangePicker as BaseDateRangePicker +} from '../../components/DateRangePicker'; export interface DateRangeProps extends FormControlProps { placeholder?: string; - disabled?: boolean; + disabled: boolean; format: string; joinValues: boolean; delimiter: string; @@ -59,7 +61,7 @@ export default class DateRangeControl extends React.Component< ? defaultValue.split(delimiter) : defaultValue; setPrinstineValue( - DateRangePicker.formatValue( + BaseDateRangePicker.formatValue( { startDate: filterDate(arr[0], data), endDate: filterDate(arr[1], data) @@ -106,7 +108,7 @@ export default class DateRangeControl extends React.Component< setPrinstineValue( arr - ? DateRangePicker.formatValue( + ? BaseDateRangePicker.formatValue( { startDate: filterDate(arr[0], data), endDate: filterDate(arr[1], data)