Skip to content

Commit ca36ffd

Browse files
committed
fix: date-picker input string not correct #2246
1 parent af69044 commit ca36ffd

File tree

9 files changed

+172
-169
lines changed

9 files changed

+172
-169
lines changed

components/_util/BaseMixin.js

+15-18
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
1+
import { getOptionProps } from './props-util';
2+
13
export default {
2-
// directives: {
3-
// ref: {
4-
// bind: function (el, binding, vnode) {
5-
// binding.value(vnode.componentInstance ? vnode.componentInstance : vnode.elm)
6-
// },
7-
// update: function (el, binding, vnode) {
8-
// binding.value(vnode.componentInstance ? vnode.componentInstance : vnode.elm)
9-
// },
10-
// unbind: function (el, binding, vnode) {
11-
// binding.value(null)
12-
// },
13-
// },
14-
// },
154
methods: {
16-
setState(state, callback) {
17-
const newState = typeof state === 'function' ? state(this.$data, this.$props) : state;
18-
// if (this.getDerivedStateFromProps) {
19-
// Object.assign(newState, this.getDerivedStateFromProps(getOptionProps(this), { ...this.$data, ...newState }, true) || {})
20-
// }
5+
setState(state = {}, callback) {
6+
let newState = typeof state === 'function' ? state(this.$data, this.$props) : state;
7+
if (this.getDerivedStateFromProps) {
8+
const s = this.getDerivedStateFromProps(getOptionProps(this), {
9+
...this.$data,
10+
...newState,
11+
});
12+
if (s === null) {
13+
return;
14+
} else {
15+
newState = { ...newState, ...(s || {}) };
16+
}
17+
}
2118
Object.assign(this.$data, newState);
2219
this.$forceUpdate();
2320
this.$nextTick(() => {

components/locale-provider/__tests__/__snapshots__/index.test.js.snap

+135-135
Large diffs are not rendered by default.

components/vc-calendar/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// based on rc-calendar 9.15.8
1+
// based on rc-calendar 9.15.10
22
import Vue from 'vue';
33
import ref from 'vue-ref';
44
import Calendar from './src/';

components/vc-calendar/src/Calendar.jsx

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const getMomentObjectIfValid = date => {
2222
};
2323

2424
const Calendar = {
25+
name: 'Calendar',
2526
props: {
2627
locale: PropTypes.object.def(enUs),
2728
format: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)]),
@@ -358,6 +359,7 @@ const Calendar = {
358359
showDateInput={props.showDateInput}
359360
timePicker={timePicker}
360361
selectedValue={sSelectedValue}
362+
timePickerDisabled={!sSelectedValue}
361363
value={sValue}
362364
disabledDate={disabledDate}
363365
okDisabled={

components/vc-calendar/src/FullCalendar.jsx

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import CommonMixin from './mixin/CommonMixin';
99
import CalendarHeader from './full-calendar/CalendarHeader';
1010
import enUs from './locale/en_US';
1111
const FullCalendar = {
12+
name: 'FullCalendar',
1213
props: {
1314
locale: PropTypes.object.def(enUs),
1415
format: PropTypes.oneOfType([PropTypes.string, PropTypes.array]),

components/vc-calendar/src/MonthCalendar.jsx

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import CalendarMixin from './mixin/CalendarMixin';
88
import CommonMixin from './mixin/CommonMixin';
99
import enUs from './locale/en_US';
1010
const MonthCalendar = {
11+
name: 'MonthCalendar',
1112
props: {
1213
locale: PropTypes.object.def(enUs),
1314
format: PropTypes.string,

components/vc-calendar/src/date/DateInput.jsx

+9-7
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ const DateInput = {
3939
},
4040
watch: {
4141
selectedValue() {
42-
this.updateState();
42+
this.setState();
4343
},
4444
format() {
45-
this.updateState();
45+
this.setState();
4646
},
4747
},
4848

@@ -62,19 +62,21 @@ const DateInput = {
6262
return dateInputInstance;
6363
},
6464
methods: {
65-
updateState() {
65+
getDerivedStateFromProps(nextProps, state) {
66+
let newState = {};
6667
if (dateInputInstance) {
6768
cachedSelectionStart = dateInputInstance.selectionStart;
6869
cachedSelectionEnd = dateInputInstance.selectionEnd;
6970
}
7071
// when popup show, click body will call this, bug!
71-
const selectedValue = this.selectedValue;
72-
if (!this.$data.hasFocus) {
73-
this.setState({
72+
const selectedValue = nextProps.selectedValue;
73+
if (!state.hasFocus) {
74+
newState = {
7475
str: formatDate(selectedValue, this.format),
7576
invalid: false,
76-
});
77+
};
7778
}
79+
return newState;
7880
},
7981
onClear() {
8082
this.setState({

components/vc-calendar/src/full-calendar/CalendarHeader.jsx

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import BaseMixin from '../../../_util/BaseMixin';
33
import { getMonthName } from '../util';
44

55
const CalendarHeader = {
6+
name: 'CalendarHeader',
67
mixins: [BaseMixin],
78
props: {
89
value: PropTypes.object,

components/vc-calendar/src/month/MonthTable.jsx

+7-8
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,10 @@ import { getTodayTime, getMonthName } from '../util/index';
55
const ROW = 4;
66
const COL = 3;
77

8-
function chooseMonth(month) {
9-
const next = this.sValue.clone();
10-
next.month(month);
11-
this.setAndSelectValue(next);
12-
}
13-
148
function noop() {}
159

1610
const MonthTable = {
11+
name: 'MonthTable',
1712
mixins: [BaseMixin],
1813
props: {
1914
cellRender: PropTypes.func,
@@ -42,7 +37,11 @@ const MonthTable = {
4237
});
4338
this.__emit('select', value);
4439
},
45-
40+
chooseMonth(month) {
41+
const next = this.sValue.clone();
42+
next.month(month);
43+
this.setAndSelectValue(next);
44+
},
4645
months() {
4746
const value = this.sValue;
4847
const current = value.clone();
@@ -107,7 +106,7 @@ const MonthTable = {
107106
<td
108107
role="gridcell"
109108
key={monthData.value}
110-
onClick={disabled ? noop : chooseMonth.bind(this, monthData.value)}
109+
onClick={disabled ? noop : () => this.chooseMonth(monthData.value)}
111110
title={monthData.title}
112111
class={classNameMap}
113112
>

0 commit comments

Comments
 (0)