Skip to content

Conversation

josepharhar
Copy link
Contributor

@josepharhar josepharhar commented Sep 29, 2025

Now that option elements can be descendants of optgroups instead of just children, the disabledness algorithm should look for ancestors intead of just a parent optgroup.

Fixes #11707

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


/form-elements.html ( diff )

Now that option elements can be descendants of optgroups instead of just
children, the disabledness algorithm should look for ancestors intead of
just a parent optgroup.

Fixes whatwg#11707
@annevk
Copy link
Member

annevk commented Sep 30, 2025

I had a peak at Chromium's code for this and HTMLOptionElement::IsDisabledFormControl() seems to do the wrong thing so I don't think this test coverage is sufficient. Or maybe I'm missing something?

source Outdated
attribute is present.</p>
data-x="attr-option-disabled">disabled</code> attribute is present or if it is a
<span>descendant</span> of an <code>optgroup</code> element whose <code
data-x="attr-optgroup-disabled">disabled</code> attribute is present.</p>
Copy link
Member

Choose a reason for hiding this comment

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

Should it also be disabled when we have <optgroup disabled><optgroup><option>?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nested optgroups are something that we decided not to support, so in this case I don't think it should be disabled. I changed the text to look for the nearest ancestor optgroup instead.

Copy link
Member

Choose a reason for hiding this comment

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

Please also add a test for this case.

Copy link
Member

@annevk annevk Oct 1, 2025

Choose a reason for hiding this comment

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

I guess I also have some other reservations. Is <select disabled><option> not disabled? What about <optgroup disabled><select><option>? (Not sure what the right answers are here, but it should be clear and we need test coverage, even if they are edge cases.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

<select disabled><option> is not disabled, and <optgroup disabled><select><option> is also not disabled with the latest commit which aborts if it finds a select element before an optgroup. I will add tests.

@josepharhar
Copy link
Contributor Author

I had a peak at Chromium's code for this and HTMLOptionElement::IsDisabledFormControl() seems to do the wrong thing so I don't think this test coverage is sufficient. Or maybe I'm missing something?

Thanks, I am fixing this in my patch which adds the WPT

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.

Maybe at some point we should formally define nearest and furthest, but this seems fine for now. Thanks!

@zcorpan
Copy link
Member

zcorpan commented Oct 1, 2025

Should this stop going through ancestors if a select element is found?

Also see handling of optgroup in https://html.spec.whatwg.org/#concept-select-option-list

@josepharhar
Copy link
Contributor Author

Should this stop going through ancestors if a select element is found?

Also see handling of optgroup in https://html.spec.whatwg.org/#concept-select-option-list

Yes, I pushed a commit to abort if a select element is found.

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.

option element disabledness works incorrectly
3 participants