Input: add clear event (#9988)

pull/9788/merge
blackmiaool 2018-03-04 13:50:25 +08:00 committed by 杨奕
parent 657f9b9c3a
commit e70c598d44
4 changed files with 34 additions and 0 deletions

View File

@ -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

View File

@ -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
| 方法名 | 说明 | 参数 |

View File

@ -284,6 +284,7 @@
clear() {
this.$emit('input', '');
this.$emit('change', '');
this.$emit('clear');
this.setCurrentValue('');
this.focus();
}

View File

@ -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();
});
});
});
});
});