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

Input: add clear event #9988

Merged
merged 1 commit into from
Mar 4, 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 examples/docs/en-US/input.md
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,7 @@ Search data from server-side.
| blur | triggers when Input blurs | (event: Event) |
| focus | triggers when Input focuses | (event: Event) |
| change | triggers when the icon inside Input value change | (value: string \| number) |
| clear | triggers when the Input is cleared by the button which generated by the "clearable" attribute | (event: Event) |

### Autocomplete Attributes

Expand Down
1 change: 1 addition & 0 deletions examples/docs/zh-CN/input.md
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,7 @@ export default {
| blur | 在 Input 失去焦点时触发 | (event: Event) |
| focus | 在 Input 获得焦点时触发 | (event: Event) |
| change | 在 Input 值改变时触发 | (value: string \| number) |
| clear | 在点击"clearable"属性生成的清空按钮时触发 | (event: Event) |

### Input Methods
| 方法名 | 说明 | 参数 |
Expand Down
1 change: 1 addition & 0 deletions packages/input/src/input.vue
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@
clear() {
this.$emit('input', '');
this.$emit('change', '');
this.$emit('clear');
this.setCurrentValue('');
this.focus();
}
Expand Down
31 changes: 31 additions & 0 deletions test/unit/specs/input.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,5 +241,36 @@ describe('Input', () => {
done();
});
});
it('event:clear', done => {
vm = createVue({
template: `
<el-input
ref="input"
placeholder="请输入内容"
clearable
:value="input">
</el-input>
`,
data() {
return {
input: 'a'
};
}
}, true);

const spyClear = sinon.spy();
const inputElm = vm.$el.querySelector('input');

// focus to show clear button
inputElm.focus();
vm.$refs.input.$on('clear', spyClear);
vm.$nextTick(_ => {
vm.$el.querySelector('.el-input__clear').click();
vm.$nextTick(_ => {
expect(spyClear.calledOnce).to.be.true;
done();
});
});
});
});
});