Skip to content

Commit 8bb9dfe

Browse files
committed
fix(picker): fix #14
1 parent c2db158 commit 8bb9dfe

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/components/Picker.vue

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ export default {
159159
data.end_ = moment(this.endDate);
160160
data.hoverStart_ = moment(this.startDate);
161161
data.hoverEnd_ = moment(this.endDate);
162+
// fix #14
163+
data.cloneStart = moment(this.startDate);
164+
data.cloneEnd = moment(this.endDate);
162165
163166
data.startText = moment(this.startDate).format(data.locale.format);
164167
data.endText = moment(this.endDate).format(data.locale.format);
@@ -245,7 +248,19 @@ export default {
245248
},
246249
clickApply () {
247250
this.pickerVisible = false;
251+
252+
// fix #14
253+
// if the use only click the picker only one time,
254+
// then close the picker directly(by clickoutside or click the activator)
255+
if (this.isFirstClick) {
256+
this.isFirstClick = false;
257+
this.start_ = this.cloneStart.clone();
258+
this.end_ = this.cloneEnd.clone();
259+
return;
260+
}
261+
248262
this.updateTextField();
263+
this.cloneForCancelUsage();
249264
this.emitChange();
250265
},
251266
clickPreset (preset) {
@@ -273,6 +288,20 @@ export default {
273288
this.startText = this.start_.format(this.locale.format);
274289
this.endText = this.end_.format(this.locale.format);
275290
},
291+
/**
292+
* fix #14
293+
* clone start and end for the following scenes, mainly for reseting the selected date to origin state:
294+
* 1. (autoApply: false) click start [or both start and end], but click the cancel button
295+
* 2. (autoApply: true) just click one time, and then click outside
296+
*
297+
* TODO (need discussion) maybe we can do this action in watch pickerVisible (from hidden to visible)
298+
* DONE we also need to do clone start and end in the watcher of ther related prop
299+
*
300+
*/
301+
cloneForCancelUsage () {
302+
this.cloneStart = this.start_.clone();
303+
this.cloneEnd = this.end_.clone();
304+
},
276305
emitChange () {
277306
const start = this.start_.clone();
278307
const end = this.end_.clone();
@@ -313,10 +342,12 @@ export default {
313342
startDate (value) {
314343
this.start_ = moment(value);
315344
this.startText = moment(value).format(this.locale.format);
345+
this.cloneStart = moment(value); // fix #14
316346
},
317347
endDate (value) {
318348
this.end_ = moment(value);
319349
this.endText = moment(value).format(this.locale.format);
350+
this.cloneEnd = moment(value); // fix #14
320351
// TODO not linked calendar
321352
},
322353
},

0 commit comments

Comments
 (0)