Skip to content

Define optgroup base appearance rendering#12201

Open
josepharhar wants to merge 5 commits intowhatwg:mainfrom
josepharhar:optgrouprendering
Open

Define optgroup base appearance rendering#12201
josepharhar wants to merge 5 commits intowhatwg:mainfrom
josepharhar:optgrouprendering

Conversation

@josepharhar
Copy link
Contributor

@josepharhar josepharhar commented Feb 25, 2026

The old text didn't explain that there is a shadow tree with an element which renders the label attribute, and that it goes away when the author provides a legend element. The UA styles for rendering the optgroup element with base appearance are still valid.

Fixes #12199

  • At least two implementers are interested (and none opposed):
    • Chrome
  • Tests are written and can be reviewed and commented upon at:
    • html/semantics/forms/the-select-element/customizable-select/select-appearance-optgroup-legend.html
    • html/semantics/forms/the-select-element/customizable-select/select-appearance-optgroup-rendering.html
  • Implementation bugs are filed:
    • Chromium: Already implemented
    • Gecko: …
    • WebKit: …
  • Corresponding HTML AAM & ARIA in HTML issues & PRs: not needed
  • MDN issue is filed: not needed
  • The top of this comment includes a clear commit message to use.

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


/rendering.html ( diff )

The old text didn't explain that there is a shadow tree with an element
which renders the label attribute, and that it goes away when the author
provides a legend element. The UA styles for rendering the optgroup
element with base appearance are still valid.

Fixes whatwg#12199
Copy link
Member

@annevk annevk left a comment

Choose a reason for hiding this comment

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

I think we should also change <optgroup>.label so it actually reflects the legend element when there is one. Seems quite strange the API would not reflect all of this. But that's probably a separate change at this point with its own tests.

source Outdated
<span>expected</span> to contain a copy of the text in the <code>optgroup</code>'s <code
data-x="attr-optgroup-label">label</code> attribute. If the <code>optgroup</code> has a child
<code>legend</code> element, then the <span>optgroup label element</span> is not
rendered.</p></li>
Copy link
Member

Choose a reason for hiding this comment

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

Why not use a slot with fallback for this? Does the legend element intentionally have different requirements than the button element. It can appear anywhere?

Copy link
Member

Choose a reason for hiding this comment

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

I also found out today that this optgroup label element is expected to have padding?

Copy link
Member

Choose a reason for hiding this comment

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

And in Chrome min-height is set to 0 but that should probably be auto? cc @nt1m

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why not use a slot with fallback for this? Does the legend element intentionally have different requirements than the button element. It can appear anywhere?

It is supposed to be first, so yeah we could do slotting instead: https://html.spec.whatwg.org/multipage/form-elements.html#the-optgroup-element

I'll go ahead and make that change here, in chromium, and WPT.

I also found out today that this optgroup label element is expected to have padding?

Yes, I made it have the same style as the legend element when rendered with base appearance. If we made it a web exposed part-like pseudo-element, which would be awesome, then we could define that in the same style rule as the legend element. Since it isn't, at least not yet, I'll add a paragraph there which says what the expected styles are.

And in Chrome min-height is set to 0 but that should probably be auto? cc @nt1m

Ah, my bad I thought that 0 was the default value. I'll change it to something better like unset.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we can first agree on the details? Since we’d have to change styles as well presumably. I’m not a 100% sold on either approach yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, how would you like to go about agreeing on the details?

Copy link
Member

Choose a reason for hiding this comment

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

I've made an attempt here: #12199 (comment)

source Outdated
<code>option</code> <span data-x="option-base-appearance">is being rendered with base
appearance</span> and the <code>option</code>'s <code data-x="attr-option-label">label</code>
attribute is not set, then the <code>option</code> is <span>expected</span> to render all of its
children rather than by displaying its <span data-x="concept-option-label">label</span>.</p>
Copy link
Member

Choose a reason for hiding this comment

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

I think we need to describe this in terms of an internal shadow tree as well. At least without that it's not clear to me how "expected to be rendered" would impact the availability of pseudo-elements.

cc @dbaron @emilio

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I replaced this with an internal shadow tree definition

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

option and optgroup rendering requirements

2 participants