A fieldset is :valid when none of its controls is invalid - #192
Open
jdalton wants to merge 1 commit into
Open
Conversation
jdalton
force-pushed
the
fix/valid-fieldset
branch
from
September 4, 2026 18:00
ddd0401 to
ef798f4
Compare
':valid' asks whether a fieldset contains a ':valid' descendant. The rule is that none of its controls may be invalid, which is a different thing: a fieldset holding no validation candidates at all is valid, and was matching neither ':valid' nor ':invalid'. A fieldset inside a disabled fieldset is the common case, since every control under it is barred from validation. Blink answers true for a fieldset's validity pseudo-classes and then loops its controls, failing only on one that is a candidate and invalid. https://github.com/chromium/chromium/blob/155.0.8041.1/third_party/blink/renderer/core/html/forms/html_field_set_element.cc#L108 References: - Spec: https://html.spec.whatwg.org/#selector-valid — a fieldset matches when all of its controls satisfy their constraints - Chromium: https://github.com/chromium/chromium/blob/155.0.8041.1/third_party/blink/renderer/core/html/forms/html_field_set_element.cc#L108 — the loop that fails only on a candidate that is invalid - Chromium: https://github.com/chromium/chromium/blob/155.0.8041.1/third_party/blink/renderer/core/css/selector_checker.cc#L2811 — ':valid' as the pair of checks - MDN: https://developer.mozilla.org/en-US/docs/Web/CSS/:valid
jdalton
force-pushed
the
fix/valid-fieldset
branch
from
September 5, 2026 02:48
ef798f4 to
22b8f06
Compare
Collaborator
Author
|
This one sits with #190 and #191 and #193, which touch the conformance fixes found by comparing against Chromium. They do not depend on each other. All seventeen in the series cherry-pick onto master in any order, and I checked that in both directions, so any one of these can land alone. The order below is the one they read best in: |
This was referenced Sep 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
:validdecides a<fieldset>by asking whether it contains a:validdescendant. The rule is the other way round: a fieldset is valid when none of its controls is invalid, which is a different question whenever a fieldset holds no validation candidates at all.Such a fieldset currently matches neither
:validnor:invalid, so it falls out of both halves of a stylesheet that uses them.The two shapes where the difference shows, and what browsers answer
fsemptyhas no controls, andfsinsits inside a disabled fieldset, so every control under it is barred from constraint validation. Chromium matches both with:valid. Before this change the engine matched neither, because neither contains a control that is itself:valid.Where browsers implement it
Blink answers
truefor a fieldset's validity pseudo-classes and then loops its controls, failing only on one that is a candidate and invalid, inhtml_field_set_element.cc#L108.:validis that pair of checks together, inselector_checker.cc#L2811.The spec text is
:valid, which says a fieldset matches when all of its descendant controls satisfy their constraints — a condition an empty fieldset meets.The change is one character of logic: the engine already had
s.first()and already compiled a:invalidresolver, so asking for the absence of an invalid descendant costs nothing new.References: the spec, the browser source, and what each part was reasoned from
This patch applies to master on its own. The sixteen in this series were checked by cherry-picking them onto master one after another, in this order and in reverse, and all sixteen land without a conflict.
html_field_set_element.cc#L108— the loop that fails only on a candidate that is invalid.selector_checker.cc#L2811—:validas the pair of checks.:valid.