Skip to content

Commit

Permalink
check for synthetic click event before dispatching click away
Browse files Browse the repository at this point in the history
Fixes phoenixframework#3040

When pressing enter inside a form, a click event is dispatched on the
corresponding submit button. Because we only set the clickStartedAtTarget
on mousedown, we would wrongly dispatch a click away.
  • Loading branch information
SteffenDE committed Jan 23, 2024
1 parent 2d573f7 commit cfd0764
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions assets/js/phoenix_live_view/live_socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,9 @@ export default class LiveSocket {
if(capture){
target = e.target.matches(`[${click}]`) ? e.target : e.target.querySelector(`[${click}]`)
} else {
// a synthetic click event (detail 0) will not have caused a mousedown event,
// therefore the clickStartedAtTarget is stale
if(e.detail === 0) this.clickStartedAtTarget = e.target
let clickStartedAtTarget = this.clickStartedAtTarget || e.target
target = closestPhxBinding(clickStartedAtTarget, click)
this.dispatchClickAway(e, clickStartedAtTarget)
Expand Down

0 comments on commit cfd0764

Please sign in to comment.