Skip to content

Make option and optgroup actually disabled inside disabled select#12205

Open
josepharhar wants to merge 4 commits intowhatwg:mainfrom
josepharhar:disabledhover
Open

Make option and optgroup actually disabled inside disabled select#12205
josepharhar wants to merge 4 commits intowhatwg:mainfrom
josepharhar:disabledhover

Conversation

@josepharhar
Copy link
Copy Markdown
Contributor

@josepharhar josepharhar commented Feb 26, 2026

This PR makes option:disabled and optgroup:disabled match when either are inside disabled select elements, without changing the behavior of other algorithms like the selectedness setting algorithm when options are inside disabled selects.

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


/semantics-other.html ( diff )

option elements can match :enabled while inside a disabled select, so
the option:enabled selectors also need to include select:enabled. More
context here: w3c/csswg-drafts#13383
@lukewarlow
Copy link
Copy Markdown
Member

Lgtm

Copy link
Copy Markdown
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 some more blame research is required here. We check disabled state of ancestor optgroup but not select. Why is that? Perhaps an oversight?

@josepharhar
Copy link
Copy Markdown
Contributor Author

I think some more blame research is required here. We check disabled state of ancestor optgroup but not select. Why is that? Perhaps an oversight?

This was added in chromium and webkit here, which references the spec:

I blamed the spec, and I got to 80aba5d which didn't seem to cite any reasons.

I'll see what tests fail if I make options become disabled when they are in a disabled select, but I anticipate that more changes would be needed to make this work, if we can at all.

@lukewarlow
Copy link
Copy Markdown
Member

When did listbox get added to the spec? One thought I had was perhaps option doesn't look at select because the assumption was you won't see the picker when select is disabled.

I can't see this being a behaviour people are relying on?

@annevk
Copy link
Copy Markdown
Member

annevk commented Mar 3, 2026

I think list boxes are about as old as the select element itself. It at least had size and multiple since its introduction to HTML in 3.2. https://www.w3.org/TR/html401/interact/forms.html#disabled suggests that the intent of <select disabled> was that it would disable the subtree. I strongly suspect this is an oversight.

@josepharhar
Copy link
Copy Markdown
Contributor Author

I took a closer look at implementing behavior where options become disabled inside disabled selects. Consider the following:

<select disabled>
  <option disabled>disabled option</option>
  <optgroup disabled label=optgroup>
    <option>option in disabled optgroup</option>
  </optgroup>
  <option>option in disabled select</option>
</select>

In current behavior, at least in chromium, "option in disabled select" gets selected by default. It could be fairly complicated to preserve this behavior, but we could try. I'd be afraid of breaking sites by changing how this currently works. Does this still seem preferrable to making the change in this PR?

@annevk
Copy link
Copy Markdown
Member

annevk commented Mar 4, 2026

Thanks for looking into it! My inclination would be to distinguish explicitly disabled and disabled and make the pseudo-class use the latter concept. (There might even be precedent for this.)

@josepharhar
Copy link
Copy Markdown
Contributor Author

We resolved on this here, which I think matches Anne's last comment: w3c/csswg-drafts#13383 (comment)

@josepharhar
Copy link
Copy Markdown
Contributor Author

Ok, I replaced the UA stylesheet changes with a change to "actually disabled" which should make option:disabled match inside a disabled select and should otherwise not change how the option's disabled state is used in other algorithms.

@josepharhar josepharhar changed the title Fix select option enabled selector Make option actually disabled inside disabled select Apr 13, 2026
@lukewarlow
Copy link
Copy Markdown
Member

lukewarlow commented Apr 13, 2026

The tests checkbox is checked but it links to a chrome cl and it's abandoned?

Also need to update the top of the PR description for the committ message to be right.

Comment thread source Outdated
@@ -79217,7 +79217,9 @@ contradict people?

<li>an <code>optgroup</code> element that has a <code data-x="attr-optgroup-disabled">disabled</code> attribute</li>
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.

Should we fix this at the same time?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

@josepharhar josepharhar changed the title Make option actually disabled inside disabled select Make option and optgroup actually disabled inside disabled select Apr 16, 2026
Comment thread source
<li>an <code>optgroup</code> element that has a <code data-x="attr-optgroup-disabled">disabled</code> attribute</li>
<li>an <code>optgroup</code> element that has a <code
data-x="attr-optgroup-disabled">disabled</code> attribute or whose nearest <span>ancestor</span>
<code>select</code> element is <span data-x="concept-fe-disabled">disabled</span></li>
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.

Do we need the same definition for ancestor select that we have for option? We probably want to exclude the same set of intermediate elements, no?

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants