Anchor the :required and :optional tests, and let :optional take a button - #191
Open
jdalton wants to merge 1 commit into
Open
Anchor the :required and :optional tests, and let :optional take a button#191jdalton wants to merge 1 commit into
jdalton wants to merge 1 commit into
Conversation
jdalton
force-pushed
the
fix/optional-anchors
branch
from
September 4, 2026 18:00
ba25907 to
da1d55f
Compare
…tton /^input|select|textarea$/ alternates '^input' with 'select' and with 'textarea$' rather than anchoring an alternation, so it accepts any element whose name begins with 'input', any name containing 'select', and any ending in 'textarea'. Both pseudo-classes use it. ':optional' also has to match button elements, which the HTML spec lists first among the ones it matches and which Blink answers true for outright. https://github.com/chromium/chromium/blob/155.0.8041.1/third_party/blink/renderer/core/html/forms/html_button_element.h#L113 A button has no required property, so '!e.required' is true for one and the list is the only change needed. References: - Spec: https://html.spec.whatwg.org/#selector-optional — the list of elements that match, which opens with button - Spec: https://html.spec.whatwg.org/#selector-required — and the list for the other half - Chromium: https://github.com/chromium/chromium/blob/155.0.8041.1/third_party/blink/renderer/core/html/forms/html_button_element.h#L113 — a button is optional outright - Chromium: https://github.com/chromium/chromium/blob/155.0.8041.1/third_party/blink/renderer/core/css/selector_checker.cc#L2751 — how ':optional' is dispatched - MDN: https://developer.mozilla.org/en-US/docs/Web/CSS/:optional
jdalton
force-pushed
the
fix/optional-anchors
branch
from
September 5, 2026 02:48
da1d55f to
ba18c39
Compare
Collaborator
Author
|
This one sits with #190 and #192 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
The patterns behind
:requiredand:optionalare written/^input|select|textarea$/i, which does not anchor an alternation. A regular expression reads that as^inputorselectortextarea$, so it accepts any element whose name starts with "input", any name containing "select", and any name ending in "textarea".:optionalalso has to match<button>elements, which it currently skips.What the loose pattern accepts, and the precedent for the fix
The alternation without a group means an element named
inputmodematches^input, and any custom element whose name containsselectmatches too. This file already writes the same kind of test correctly elsewhere —:emptyand:placeholder-shownuse/^(?:input|textarea)$/i— so this change makes the two form patterns match that existing style.The same shape of bug was fixed in
:linkand:any-link, where/^a|area$/iaccepted<abbr href="…">.Why a button is optional, and where browsers say so
The HTML spec lists button elements first among the ones
:optionalmatches, before inputs, selects and textareas. Blink answerstruefor a button without asking anything else, inhtml_button_element.h#L113, reached fromselector_checker.cc#L2751.A button has no
requiredproperty, so!e.requiredis already true for one and adding it to the list is the whole change.button:optionalreturns the button afterwards, where it returned nothing before.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_button_element.h#L113— a button is optional outright.selector_checker.cc#L2751— how:optionalis dispatched.:optional.