picker: fix clear value

pull/7746/head
wacky6.AriesMBP 2017-10-26 15:20:59 +11:00 committed by 杨奕
parent 00e8c7454f
commit 07acf66a69
5 changed files with 31 additions and 8 deletions

View File

@ -406,7 +406,7 @@
this.maxDate = null; this.maxDate = null;
this.leftDate = calcDefaultValue(this.defaultValue)[0]; this.leftDate = calcDefaultValue(this.defaultValue)[0];
this.rightDate = nextMonth(this.leftDate); this.rightDate = nextMonth(this.leftDate);
this.handleConfirm(false); this.$emit('pick', null);
}, },
handleChangeRange(val) { handleChangeRange(val) {

View File

@ -214,7 +214,7 @@
handleClear() { handleClear() {
this.date = this.defaultValue ? new Date(this.defaultValue) : new Date(); this.date = this.defaultValue ? new Date(this.defaultValue) : new Date();
this.$emit('pick'); this.$emit('pick', null);
}, },
emit(value, ...args) { emit(value, ...args) {

View File

@ -150,7 +150,7 @@
methods: { methods: {
handleClear() { handleClear() {
this.$emit('pick', []); this.$emit('pick', null);
}, },
handleCancel() { handleCancel() {

View File

@ -90,7 +90,7 @@
}, },
handleClear() { handleClear() {
this.$emit('pick'); this.$emit('pick', null);
}, },
scrollToOption(selector = '.selected') { scrollToOption(selector = '.selected') {

View File

@ -101,13 +101,14 @@ describe('DatePicker', () => {
setTimeout(_ => { setTimeout(_ => {
const $el = vm.$refs.compo.picker.$el; const $el = vm.$refs.compo.picker.$el;
$el.querySelector('td.available').click(); $el.querySelector('td.available').click();
vm.$nextTick(_ => { setTimeout(_ => {
vm.$el.querySelector('.el-input__icon').click(); vm.$refs.compo.showClose = true;
vm.$refs.compo.handleClickIcon({ stopPropagation: () => null });
setTimeout(_ => { setTimeout(_ => {
expect(vm.value).to.empty; expect(vm.value).to.equal(null);
done(); done();
}, DELAY); }, DELAY);
}); }, DELAY);
}, DELAY); }, DELAY);
}); });
@ -1175,6 +1176,28 @@ describe('DatePicker', () => {
done(); done();
}, DELAY); }, DELAY);
}); });
it('clear value', done => {
vm = createVue({
template: '<el-date-picker type="daterange" v-model="value" ref="compo" />',
data() {
return {
value: [new Date(2000, 9, 1), new Date(2000, 9, 2)]
};
}
}, true);
vm.$el.querySelector('input').focus();
setTimeout(_ => {
vm.$refs.compo.showClose = true;
vm.$refs.compo.handleClickIcon({ stopPropagation: () => null });
setTimeout(_ => {
expect(vm.value).to.equal(null);
done();
}, DELAY);
}, DELAY);
});
}); });
describe('type:datetimerange', () => { describe('type:datetimerange', () => {