Skip to content

Commit

Permalink
merge value attribute as long as the property matches (#3058)
Browse files Browse the repository at this point in the history
We exclude the value from being merged on focused inputs, because the
user's input should always win.
We can still assign it as long as the value property is the same, though.
This prevents a situation where the updated hook is not being triggered
when an input is back in its "original state", because the attribute
was never changed.

Fixes #2163.
  • Loading branch information
SteffenDE committed Jan 31, 2024
1 parent cfe233d commit 3565114
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions assets/js/phoenix_live_view/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,18 @@ let DOM = {
if(target.getAttribute(name) !== sourceValue && (!isIgnored || (isIgnored && name.startsWith("data-")))){
target.setAttribute(name, sourceValue)
}
} else {
// We exclude the value from being merged on focused inputs, because the
// user's input should always win.
// We can still assign it as long as the value property is the same, though.
// This prevents a situation where the updated hook is not being triggered
// when an input is back in its "original state", because the attribute
// was never changed, see:
// https://github.com/phoenixframework/phoenix_live_view/issues/2163
if(name === "value" && target.value === source.value){
// actually set the value attribute to sync it with the value property
target.setAttribute("value", source.getAttribute(name))
}
}
}

Expand Down

0 comments on commit 3565114

Please sign in to comment.