mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-05-25 07:49:15 +08:00
fix(Field): should not submit form on enter (#6240)
This commit is contained in:
parent
a7968c5f6e
commit
09fdde8c56
@ -353,10 +353,15 @@ export default createComponent({
|
|||||||
},
|
},
|
||||||
|
|
||||||
onKeypress(event) {
|
onKeypress(event) {
|
||||||
// trigger blur after click keyboard search button
|
const ENTER_CODE = 13;
|
||||||
/* istanbul ignore next */
|
|
||||||
if (this.type === 'search' && event.keyCode === 13) {
|
if (event.keyCode === ENTER_CODE) {
|
||||||
this.blur();
|
preventDefault(event);
|
||||||
|
|
||||||
|
// trigger blur after click keyboard search button
|
||||||
|
if (this.type === 'search') {
|
||||||
|
this.blur();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.$emit('keypress', event);
|
this.$emit('keypress', event);
|
||||||
|
@ -342,3 +342,17 @@ test('colon prop', () => {
|
|||||||
});
|
});
|
||||||
expect(wrapper).toMatchSnapshot();
|
expect(wrapper).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should blur search input on enter', () => {
|
||||||
|
const wrapper = mount(Field);
|
||||||
|
const input = wrapper.find('input');
|
||||||
|
|
||||||
|
input.element.focus();
|
||||||
|
|
||||||
|
input.trigger('keypress.enter');
|
||||||
|
expect(wrapper.emitted('blur')).toBeFalsy();
|
||||||
|
|
||||||
|
wrapper.setProps({ type: 'search' });
|
||||||
|
input.trigger('keypress.enter');
|
||||||
|
expect(wrapper.emitted('blur')).toBeTruthy();
|
||||||
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user