mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
[new feature] Field: add click event
This commit is contained in:
parent
a8a18505a6
commit
9a32a4a35d
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
##### Field
|
##### Field
|
||||||
|
|
||||||
|
- 新增`click`事件
|
||||||
- 新增`clickable`属性
|
- 新增`clickable`属性
|
||||||
|
|
||||||
##### Stepper
|
##### Stepper
|
||||||
|
@ -15,9 +15,9 @@
|
|||||||
v-model="username"
|
v-model="username"
|
||||||
:label="$t('username')"
|
:label="$t('username')"
|
||||||
:placeholder="$t('usernamePlaceholder')"
|
:placeholder="$t('usernamePlaceholder')"
|
||||||
|
required
|
||||||
clearable
|
clearable
|
||||||
right-icon="question-o"
|
right-icon="question-o"
|
||||||
required
|
|
||||||
@click-right-icon="$toast('question')"
|
@click-right-icon="$toast('question')"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
@ -152,6 +152,7 @@ Field support all native events of input tag,such as `focus`、`blur`、`keypr
|
|||||||
| Event | Description | Parameters |
|
| Event | Description | Parameters |
|
||||||
|------|------|------|
|
|------|------|------|
|
||||||
| input | Triggered when value changed | - |
|
| input | Triggered when value changed | - |
|
||||||
|
| click | Triggered when click field | - |
|
||||||
| clear | Triggered when click clear icon | - |
|
| clear | Triggered when click clear icon | - |
|
||||||
| click-left-icon | Triggered when click the left icon of Field | - |
|
| click-left-icon | Triggered when click the left icon of Field | - |
|
||||||
| click-right-icon | Triggered when click the right icon of Field | - |
|
| click-right-icon | Triggered when click the right icon of Field | - |
|
||||||
|
@ -59,13 +59,17 @@ export default sfc({
|
|||||||
},
|
},
|
||||||
|
|
||||||
listeners() {
|
listeners() {
|
||||||
return {
|
const listeners = {
|
||||||
...this.$listeners,
|
...this.$listeners,
|
||||||
input: this.onInput,
|
input: this.onInput,
|
||||||
keypress: this.onKeypress,
|
keypress: this.onKeypress,
|
||||||
focus: this.onFocus,
|
focus: this.onFocus,
|
||||||
blur: this.onBlur
|
blur: this.onBlur
|
||||||
};
|
};
|
||||||
|
|
||||||
|
delete listeners.click;
|
||||||
|
|
||||||
|
return listeners;
|
||||||
},
|
},
|
||||||
|
|
||||||
labelStyle() {
|
labelStyle() {
|
||||||
@ -130,6 +134,10 @@ export default sfc({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
onClick(event) {
|
||||||
|
this.$emit('click', event);
|
||||||
|
},
|
||||||
|
|
||||||
onClickLeftIcon() {
|
onClickLeftIcon() {
|
||||||
this.$emit('click-left-icon');
|
this.$emit('click-left-icon');
|
||||||
},
|
},
|
||||||
@ -272,6 +280,7 @@ export default sfc({
|
|||||||
'min-height': this.type === 'textarea' && !this.autosize
|
'min-height': this.type === 'textarea' && !this.autosize
|
||||||
})}
|
})}
|
||||||
scopedSlots={scopedSlots}
|
scopedSlots={scopedSlots}
|
||||||
|
onClick={this.onClick}
|
||||||
>
|
>
|
||||||
<div class={bem('body')}>
|
<div class={bem('body')}>
|
||||||
{this.renderInput()}
|
{this.renderInput()}
|
||||||
|
@ -10,6 +10,13 @@ test('input event', () => {
|
|||||||
expect(wrapper.emitted('input')[0][0]).toEqual('1');
|
expect(wrapper.emitted('input')[0][0]).toEqual('1');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('click event', () => {
|
||||||
|
const wrapper = mount(Field);
|
||||||
|
|
||||||
|
wrapper.trigger('click');
|
||||||
|
expect(wrapper.emitted('click')[0][0]).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
test('click icon event', () => {
|
test('click icon event', () => {
|
||||||
const wrapper = mount(Field, {
|
const wrapper = mount(Field, {
|
||||||
propsData: {
|
propsData: {
|
||||||
|
@ -155,6 +155,7 @@ Field 默认支持 Input 标签所有的原生事件,如 `focus`、`blur`、`k
|
|||||||
| 事件 | 说明 | 回调参数 |
|
| 事件 | 说明 | 回调参数 |
|
||||||
|------|------|------|
|
|------|------|------|
|
||||||
| input | 输入框内容变化时触发 | - |
|
| input | 输入框内容变化时触发 | - |
|
||||||
|
| click | 点击时触发 | - |
|
||||||
| clear | 点击清除按钮后触发 | - |
|
| clear | 点击清除按钮后触发 | - |
|
||||||
| click-left-icon | 点击头部图标时触发 | - |
|
| click-left-icon | 点击头部图标时触发 | - |
|
||||||
| click-right-icon | 点击尾部图标时触发 | - |
|
| click-right-icon | 点击尾部图标时触发 | - |
|
||||||
|
Loading…
x
Reference in New Issue
Block a user