Skip to content

Make <option> and <optgroup> share a text content algorithm - #12232

Merged
annevk merged 1 commit into
mainfrom
annevk/option-optgroup-parity
Sep 14, 2026
Merged

annevk merged 1 commit into
mainfrom
annevk/option-optgroup-parity

Conversation

@annevk

@annevk annevk commented Mar 6, 2026

Copy link
Copy Markdown
Member

This also fixes several other issues:

  1. Be more specific about which legend element we care about.
  2. Address the label attribute being missing.
  3. <img alt> offers replacement text and as such adding spaces on both sides is wrong.
  4. When includeAltText is false we still want to skip the descendants of img elements.

This does not fix an existing issue which is that user agents should be allowed to render the img elements as well if they want to.

(See WHATWG Working Mode: Changes for more details.)


/form-elements.html ( diff )
/rendering.html ( diff )

@annevk
annevk requested review from josepharhar and mfreed7 March 6, 2026 14:49
@annevk annevk added the topic: select The <select> element label Mar 6, 2026
@josepharhar

Copy link
Copy Markdown
Contributor

Not the first child if it is a legend element.

The content model of the optgroup element only allows a legend if it is the first child though, right?

Otherwise this change looks ok to me

@annevk

annevk commented Mar 10, 2026

Copy link
Copy Markdown
Member Author

The content model has no bearing on browsers. However, it seems that in #12199 we are thinking of changing the standard to require that only the first element child is checked for being a legend element in which case this also needs to change.

So I guess I'll wait with this to see how your experiment pans out and if it pans out favorably I will update the text.

@annevk

annevk commented Jul 7, 2026

Copy link
Copy Markdown
Member Author

Now that #12199 is fixed I've rebased this. @josepharhar @keithamus could you please review?

@josepharhar josepharhar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good but does web-platform-tests/wpt#61109 cover all of the changes here?

@annevk

annevk commented Jul 13, 2026

Copy link
Copy Markdown
Member Author

I'm not entirely sure how we can test some of the behavior that's mostly still implementation-defined. Any ideas?

@josepharhar

Copy link
Copy Markdown
Contributor

I see, yeah this just changes how the legend element in an optgroup is converted into a text representation for appearance:auto, which we can't test because of the native picker, right?

The appearance:auto listbox select elements in chromium are actually rendering the legend element instead of a text representation of them, so I wouldn't be able to test it that way either.

This also fixes several other issues:

1. Be more specific about which legend element we care about.
2. Address the label attribute being missing.
3. <img alt> offers replacement text and as such adding spaces on both sides is wrong.
4. When includeAltText is false we still want to skip the descendants of img elements.

This does not fix an existing issue which is that user agents should be allowed to render the img elements as well if they want to.
@annevk
annevk force-pushed the annevk/option-optgroup-parity branch from a5c2ef8 to 624fefe Compare September 14, 2026 15:03

@keithamus keithamus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM.

annevk added a commit to web-platform-tests/wpt that referenced this pull request Sep 14, 2026
@annevk
annevk merged commit 8a729be into main Sep 14, 2026
2 checks passed
@annevk
annevk deleted the annevk/option-optgroup-parity branch September 14, 2026 16:04
annevk added a commit to annevk/WebKit that referenced this pull request Sep 15, 2026
https://bugs.webkit.org/show_bug.cgi?id=324223

Reviewed by NOBODY (OOPS!).

Implements whatwg/html#12232, which replaces
"collect option text" with "get HTML-aware text content", now shared
between <option> and <optgroup>.

Getting an <optgroup>'s label now only considers a <legend> that is the
optgroup's first element child, falling back to the label attribute and
then the empty string.

The label element has to look like a <legend>, which is the entire
reason it exists, so it now shares their user agent style rule through
an -internal-optgroup-label user agent part rather than carrying two
inline padding properties that had drifted from that rule.

fast/forms/select/optgroup-option-shadow-tree.html expected the label
element to exist only for a label attribute, so update it, and cover a
<legend> that is not the first element child while there.

The reference tests are not always passing due to the slight shift of the
picker icon as noted in TestExpectations.

Test: imported/w3c/web-platform-tests/html/semantics/forms/the-select-element/customizable-select/select-appearance-optgroup-legend-not-first.html

Upstream: web-platform-tests/wpt#61109
webkit-commit-queue pushed a commit to annevk/WebKit that referenced this pull request Sep 16, 2026
https://bugs.webkit.org/show_bug.cgi?id=324223

Reviewed by Tim Nguyen.

Implements whatwg/html#12232, which replaces
"collect option text" with "get HTML-aware text content", now shared
between <option> and <optgroup>.

Getting an <optgroup>'s label now only considers a <legend> that is the
optgroup's first element child, falling back to the label attribute and
then the empty string.

The label element has to look like a <legend>, which is the entire
reason it exists, so it now shares their user agent style rule through
an -internal-optgroup-label user agent part rather than carrying two
inline padding properties that had drifted from that rule.

fast/forms/select/optgroup-option-shadow-tree.html expected the label
element to exist only for a label attribute, so update it, and cover a
<legend> that is not the first element child while there.

The reference tests are not always passing due to the slight shift of the
picker icon as noted in TestExpectations.

Test: imported/w3c/web-platform-tests/html/semantics/forms/the-select-element/customizable-select/select-appearance-optgroup-legend-not-first.html

Upstream: web-platform-tests/wpt#61109
Canonical link: https://commits.webkit.org/321227@main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic: select The <select> element

Development

Successfully merging this pull request may close these issues.

4 participants