Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

date-picker: fix change event on clear #9986

Merged
merged 1 commit into from
Mar 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/date-picker/src/picker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,7 @@ export default {
handleClickIcon(event) {
if (this.readonly || this.pickerDisabled) return;
if (this.showClose) {
this.valueOnOpen = this.value;
event.stopPropagation();
this.emitInput(null);
this.emitChange(null);
Expand Down
28 changes: 28 additions & 0 deletions test/unit/specs/date-picker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,34 @@ describe('DatePicker', () => {
}, DELAY);
});

it('change event: when clear(), without opening picker', done => {
vm = createVue({
template: `
<el-date-picker
ref="compo"
v-model="value"
/>`,
data() {
return {
value: new Date()
};
}
}, true);

const spy = sinon.spy();
vm.$refs.compo.$on('change', spy);

setTimeout(_ => {
vm.$refs.compo.showClose = true;
vm.$refs.compo.handleClickIcon({ stopPropagation: () => null });
setTimeout(_ => {
expect(spy.calledOnce).to.equal(true);
expect(spy.calledWith(null)).to.equal(true);
done();
}, DELAY);
}, DELAY);
});

describe('input event', () => {
// mimic standard <select>'s behavior
// emit input if and only if value changes
Expand Down