Skip to content

Commit

Permalink
LibWeb: Add missing handler in affected_by_invalidation_property()
Browse files Browse the repository at this point in the history
...for :placeholder-shown pseudo-class.
  • Loading branch information
kalenikaliaksandr committed Jan 25, 2025
1 parent 30dc919 commit a9603b7
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Libraries/LibWeb/DOM/Element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1169,6 +1169,14 @@ bool Element::affected_by_invalidation_property(CSS::InvalidationSet::Property c
// FIXME: This could be narrowed down to return true only if element is actually checked.
return is<HTML::HTMLInputElement>(*this) || is<HTML::HTMLOptionElement>(*this);
}
case CSS::PseudoClass::PlaceholderShown: {
if (is<HTML::HTMLInputElement>(*this) && has_attribute(HTML::AttributeNames::placeholder)) {
auto const& input_element = static_cast<HTML::HTMLInputElement const&>(*this);
return input_element.placeholder_element() && input_element.placeholder_value().has_value();
}
// - FIXME: textarea elements that have a placeholder attribute whose value is currently being presented to the user.
return false;
}
default:
VERIFY_NOT_REACHED();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PASS (didn't crash)
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>

<head>
<script src="include.js"></script>
<style>
#b input:placeholder-shown {
border: 2px dashed red;
background-color: #ffecec;
}
</style>
</head>

<body>
<div id="a"><input type="text" placeholder=""></input></div>
<script>
test(() => {
document.documentElement.offsetHeight; // force style recalculation
const a = document.getElementById('a');
a.id = 'b';
println("PASS (didn't crash)");
});
</script>
</body>

</html>

0 comments on commit a9603b7

Please sign in to comment.