diff --git a/packages/date-picker/src/picker.vue b/packages/date-picker/src/picker.vue index 28f37403d..9368c6a20 100644 --- a/packages/date-picker/src/picker.vue +++ b/packages/date-picker/src/picker.vue @@ -390,12 +390,7 @@ export default { } else { this.hidePicker(); this.emitChange(this.value); - // flush user input if it is parsable - // this.displayValue here is not a typo, it merges text for both panels in range mode - const parsedValue = this.parseString(this.displayValue); - if (this.userInput && parsedValue && this.isValidValue(parsedValue)) { - this.userInput = null; - } + this.userInput = null; this.dispatch('ElFormItem', 'el.form.blur'); this.$emit('blur', this); this.blur(); diff --git a/test/unit/specs/date-picker.spec.js b/test/unit/specs/date-picker.spec.js index 63784fd06..c8f842fcd 100644 --- a/test/unit/specs/date-picker.spec.js +++ b/test/unit/specs/date-picker.spec.js @@ -261,6 +261,33 @@ describe('DatePicker', () => { }, DELAY); }); + it('nuke invalid input on close', done => { + vm = createVue({ + template: '', + data() { + return { + value: '2010-10-01' + }; + } + }, true); + + const compo = vm.$refs.compo; + const input = compo.$el.querySelector('input'); + input.blur(); + input.focus(); + + setTimeout(_ => { + compo.userInput = 'abc'; + compo.handleChange(); // simplified test + compo.handleClose(); + setTimeout(_ => { + expect(input.value).to.equal('2010-10-01'); + expect(vm.value).to.equal('2010-10-01'); + done(); + }, DELAY); + }, DELAY); + }); + it('select datetime with defaultTime', done => { vm = createVue({ template: `