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) {
|
||||
// trigger blur after click keyboard search button
|
||||
/* istanbul ignore next */
|
||||
if (this.type === 'search' && event.keyCode === 13) {
|
||||
this.blur();
|
||||
const ENTER_CODE = 13;
|
||||
|
||||
if (event.keyCode === ENTER_CODE) {
|
||||
preventDefault(event);
|
||||
|
||||
// trigger blur after click keyboard search button
|
||||
if (this.type === 'search') {
|
||||
this.blur();
|
||||
}
|
||||
}
|
||||
|
||||
this.$emit('keypress', event);
|
||||
|
@ -342,3 +342,17 @@ test('colon prop', () => {
|
||||
});
|
||||
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