diff --git a/packages/amis-ui/src/components/calendar/Calendar.tsx b/packages/amis-ui/src/components/calendar/Calendar.tsx index 945502bd976..eb12f517db4 100644 --- a/packages/amis-ui/src/components/calendar/Calendar.tsx +++ b/packages/amis-ui/src/components/calendar/Calendar.tsx @@ -137,6 +137,7 @@ interface BaseDatePickerProps { interface BaseDatePickerState { displayForamt?: boolean | string; currentView: string; + initView: string; viewDate: moment.Moment; selectedDate: moment.Moment; inputValue?: string; @@ -371,6 +372,7 @@ class BaseDatePicker extends React.Component< state.currentView = this.props.dateFormat ? this.props.viewMode || state.updateOn || 'days' : this.props.viewMode || 'time'; + state.initView = state.currentView; this.state = state; this.onClick = this.onClick.bind(this); @@ -437,7 +439,6 @@ class BaseDatePicker extends React.Component< 'inputFormat', 'displayForamt', 'onChange', - 'onClose', 'requiredConfirm', 'classPrefix', 'prevIcon', @@ -691,10 +692,16 @@ class BaseDatePicker extends React.Component< if (!this.props.value) { this.setState({ selectedDate: date, + viewDate: date, inputValue: date!.format(this.state.displayForamt as string) }); } this.props.onChange && this.props.onChange(date); + this.onClose(); + }; + + onClose = () => { + this.setState({currentView: this.state.initView}); this.props.onClose && this.props.onClose(); }; @@ -731,6 +738,7 @@ class BaseDatePicker extends React.Component< } viewProps.onConfirm = this.onConfirm; + viewProps.onClose = this.onClose; viewProps.getDateBoundary = this.getDateBoundary; viewProps.getColumns = this.getColumns; viewProps.timeCell = this.timeCell;