Skip to content

Update content model for customizable select #10586

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 48 commits into
base: main
Choose a base branch
from

Conversation

josepharhar
Copy link
Contributor

@josepharhar josepharhar commented Aug 28, 2024

This PR updates the content model for the <select>, <option>, and <optgroup> elements in support of customizable <select>.

The major additions are:

  • <select> and <optgroup> can contain <div> elements.
  • <option> elements can contain <div> and non-interactive phrasing content.
  • <optgroup> can have a child <legend> to represent its label.

Fixes #10317

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


/dom.html ( diff )
/form-elements.html ( diff )
/grouping-content.html ( diff )
/index.html ( diff )
/indices.html ( diff )
/rendering.html ( diff )
/scripting.html ( diff )
/text-level-semantics.html ( diff )

This PR updated the content model for the <select>, <option>, and
<optgroup> elements in support of customizable <select>.

Fixes whatwg#10317
@zcorpan zcorpan self-requested a review September 12, 2024 16:07
@zcorpan
Copy link
Member

zcorpan commented Sep 16, 2024

Is the idea to allow <select><div><h1><option> and such? Or only <select><div><div><option>?

If the former, you need to change the definition of phrasing content to include "option (if it is a descendant of a select element), optgroup (if it is a descendant of a select element)".

If the latter, you need to change the content model if div and span to switch on whether there's an ancestor select element, and if so allow "select element inner content elements". (But still disallow nesting of optgroup and option)

@zcorpan zcorpan mentioned this pull request Sep 16, 2024
5 tasks
@josepharhar
Copy link
Contributor Author

Is the idea to allow <select><div><h1><option> and such? Or only <select><div><div><option>?

If the former, you need to change the definition of phrasing content to include "option (if it is a descendant of a select element), optgroup (if it is a descendant of a select element)".

If the latter, you need to change the content model if div and span to switch on whether there's an ancestor select element, and if so allow "select element inner content elements". (But still disallow nesting of optgroup and option)

h1 elements are not supposed to be part of the content model, so I implemented the div and span switching by pulling out the content models for option and optgroup and using them in div and span.

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.

This could use some examples. Or are we adding those as part of another PR?

scottaohara added a commit to w3c/aria that referenced this pull request Oct 22, 2024
In regards to the updated content model for the select element and its allowed children, an `optgroup` can have a `legend` element as its first child, and this `legend` needs to be able to name the `optgroup` similarly to how a `legend` names a `fieldset`.

see:
whatwg/html#10586
@josepharhar
Copy link
Contributor Author

This could use some examples. Or are we adding those as part of another PR?

I started a follow up here: https://github.com/whatwg/html/compare/main...josepharhar:html:selectexamples?expand=1

@scottaohara
Copy link
Collaborator

This could use some examples. Or are we adding those as part of another PR?

I started a follow up here: https://github.com/whatwg/html/compare/main...josepharhar:html:selectexamples?expand=1

thanks @josepharhar - give me a shout when these are finished, and i can help review and/or add on as need be.

@josepharhar
Copy link
Contributor Author

In order to resolve the remaining two open comment threads, I added notes about the content model:

I originally had notes about the content model which were placed directly after the content model itself, but I was told not to do that and to put the notes where the prose about the content model is. I'm not sure where such prose exists, so I just added the notes to the very end of the option element and select element sections: #10586 (comment)

Copy link
Member

@domfarolino domfarolino left a comment

Choose a reason for hiding this comment

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

It looks like everything has been addressed with this PR for a bit now. The contents look good to me, thanks for resolving the last two bits in #10586 (comment) @josepharhar and adding more detail to the commit message in the OP.

I'll plan on merging this towards the end of next week, provided the one nit I found gets resolved and there are no further substantial reviews.

source Outdated
<p><dfn><code>select</code> element inner content elements</dfn> are the elements which are
allowed as descendants of <code>select</code> elements.</p>

<p>The following are <span><code>select</code> element inner content elements</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.

#10633 seems to expect that the select element can have a button element child. Shouldn't that be described here? Is that PR going to be changed and rebased after this lands? It would be good to see the overall plan here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This PR lets the select element have a button child, and the <selectedcontent> PR lets selectedcontent be put inside the button element. Besides merging this one before the selectedcontent PR, what changes do you think should be made?

Copy link
Member

@annevk annevk Apr 16, 2025

Choose a reason for hiding this comment

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

I see, the button element is handled outside this list.

Comment on lines +54671 to +54676
<div class="note">
<p>The first child <code>button</code> element as allowed by the content model of
<code>select</code> is not a submit button. It is used to replace the in-page rendering of the
<code>select</code> element. Its form submission behavior is prevented because it has inert set
in the UA stylesheet.</p>
</div>
Copy link
Member

Choose a reason for hiding this comment

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

This presupposes a feature that doesn't exist. Can we solve this differently? Perhaps we can forcibly make this not a submit button and also reflect that in the type getter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we could easily solve this differently by just saying that the first child <button> is inert instead of putting that in the UA stylesheet.

Inertness helps more than just making the button not a submit button, such as ensuring accessibility by not allowing nested interactive content. I could also forcibly make this not a submit button, but in practice that doesn't matter if the button is inert.

What do you think?

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.

Content model and 'what' to render for stylable <select> elements
8 participants