Skip to content

Commit

Permalink
LibWeb: Invalidate input element style on focus change
Browse files Browse the repository at this point in the history
The style of input and textarea elements is now invalidated when focus
is changed to a new element. This ensures any `:focus` selectors are
applied correctly.
  • Loading branch information
tcl3 committed Jul 7, 2024
1 parent 1140c96 commit 0331cb6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
11 changes: 8 additions & 3 deletions Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1098,16 +1098,21 @@ void HTMLInputElement::update_slider_thumb_element()

void HTMLInputElement::did_receive_focus()
{
auto navigable = document().navigable();
if (!navigable)
return;
if (!m_text_node)
return;
m_text_node->invalidate_style();
auto navigable = document().navigable();
if (!navigable) {
return;
}
navigable->set_cursor_position(DOM::Position::create(realm(), *m_text_node, 0));
}

void HTMLInputElement::did_lose_focus()
{
if (m_text_node)
m_text_node->invalidate_style();

commit_pending_changes();
}

Expand Down
11 changes: 8 additions & 3 deletions Userland/Libraries/LibWeb/HTML/HTMLTextAreaElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,21 @@ void HTMLTextAreaElement::visit_edges(Cell::Visitor& visitor)

void HTMLTextAreaElement::did_receive_focus()
{
auto navigable = document().navigable();
if (!navigable)
return;
if (!m_text_node)
return;
m_text_node->invalidate_style();
auto navigable = document().navigable();
if (!navigable) {
return;
}
navigable->set_cursor_position(DOM::Position::create(realm(), *m_text_node, 0));
}

void HTMLTextAreaElement::did_lose_focus()
{
if (m_text_node)
m_text_node->invalidate_style();

// The change event fires when the value is committed, if that makes sense for the control,
// or else when the control loses focus
queue_an_element_task(HTML::Task::Source::UserInteraction, [this] {
Expand Down

0 comments on commit 0331cb6

Please sign in to comment.