LibWeb: Hide inner text of input element when showing placeholder

This commit is contained in:
Bastiaan van der Plaat 2024-03-15 18:22:57 +01:00 committed by Tim Flynn
parent b4bae912c9
commit 4205ac778f
Notes: sideshowbarker 2024-07-17 02:21:14 +09:00
4 changed files with 68 additions and 4 deletions

View file

@ -601,11 +601,12 @@ void HTMLInputElement::update_placeholder_visibility()
{
if (!m_placeholder_element)
return;
auto placeholder_text = this->placeholder_value();
if (placeholder_text.has_value()) {
if (this->placeholder_value().has_value()) {
MUST(m_placeholder_element->style_for_bindings()->set_property(CSS::PropertyID::Display, "block"sv));
MUST(m_inner_text_element->style_for_bindings()->set_property(CSS::PropertyID::Display, "none"sv));
} else {
MUST(m_placeholder_element->style_for_bindings()->set_property(CSS::PropertyID::Display, "none"sv));
MUST(m_inner_text_element->style_for_bindings()->set_property(CSS::PropertyID::Display, "block"sv));
}
}
@ -767,7 +768,7 @@ void HTMLInputElement::create_text_input_shadow_tree()
m_placeholder_element = MUST(DOM::create_element(document(), HTML::TagNames::div, Namespace::HTML));
m_placeholder_element->set_use_pseudo_element(CSS::Selector::PseudoElement::Type::Placeholder);
MUST(m_placeholder_element->set_attribute(HTML::AttributeNames::style, R"~~~(
flex: 1;
width: 100%;
height: 1lh;
)~~~"_string));
MUST(element->append_child(*m_placeholder_element));
@ -779,7 +780,7 @@ void HTMLInputElement::create_text_input_shadow_tree()
m_inner_text_element = MUST(DOM::create_element(document(), HTML::TagNames::div, Namespace::HTML));
MUST(m_inner_text_element->set_attribute(HTML::AttributeNames::style, R"~~~(
flex: 1;
width: 100%;
height: 1lh;
)~~~"_string));
MUST(element->append_child(*m_inner_text_element));