-
-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Description
Vue version
3.4.36 / 3.5.0-alpha.5 / latest commit
Link to minimal reproduction
Steps to reproduce
- Create a form with @submit.prevent="fn1".
- fn1 =
function fn1() { alert('fn1'); }
- Create a button with type="submit" inside of the form.
- Create an input inside of the form with @keydown.enter="fn2".
- fn2 =
function fn2 (event) { alert('fn2'); event.stopImmediatePropagation(); }
- Press enter whilst focusing the input.
What is expected?
A dialog would show "fn2" and when you click Ok no further dialog should appear.
What is actually happening?
A dialog will show "fn2" and when you click Ok a second dialog will show "fn1".
System Info
No response
Any additional comments?
In terms of submitting the form by using the enter key whilst focusing an input, the specifications describe this as implicit submission of the SubmitEvent.
The event modifiers documentation mentions that one can .stop further propagation of the event but this does not prevent propagation to other event-handlers of the current element. In order to prevent other listeners of the same event from being called one should use event.stopImmediatePropagation()
.
There are 3 closed issues that reference this method of the event: #916, #3643, #10179.
In 3643 @LinusBorg had mentioned the surrounding difficulties that are involved in making Vue aware of that this was called in order to stop calling the rest of the listeners.
And in 10179 they had also mentioned that we would need call event.stopImmediatePropagation() in the child handler.
The above comment is mentioned as being the solution but it does not seem to work in this instance. Or is it simply the case of me having missed something within my thought process?