Skip to content

Define customizable <select> #10548

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 180 commits into
base: main
Choose a base branch
from
Open

Conversation

josepharhar
Copy link
Contributor

@josepharhar josepharhar commented Aug 5, 2024

This defines several concepts related to customizable <select>:

  • Relaxing the HTML parser to allow more tags inside <select>
  • Updating the content model to allow more elements inside <select> and related elements.
  • Defines rendering and some interactions for base appearance for <select>
  • Adds the <selectedcontent> HTML element
  • Adds a UA stylesheet for <select> with base appearance

Closes #9799
Closes #10557
Closes #10310
Closes #10586
Closes #10317
Closes #10629
Closes #10633
Closes #10520
Closes #10670
Closes #10520
Closes #10762


/dom.html ( diff )
/form-control-infrastructure.html ( diff )
/form-elements.html ( diff )
/grouping-content.html ( diff )
/index.html ( diff )
/indices.html ( diff )
/infrastructure.html ( diff )
/interactive-elements.html ( diff )
/parsing.html ( diff )
/references.html ( diff )
/rendering.html ( diff )
/scripting.html ( diff )
/text-level-semantics.html ( diff )

@josepharhar josepharhar force-pushed the selectcomplete branch 2 times, most recently from 4691e13 to bef9083 Compare August 7, 2024 22:31
@josepharhar
Copy link
Contributor Author

FYI: I am likely going to remove the author-provided datalist and fallback UA button in this PR soon based on recent discussions, which will likely reduce the number of changes and complexity.

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

Fixes whatwg#10317
@josepharhar josepharhar force-pushed the selectcomplete branch 2 times, most recently from 939fe27 to 04e9fcd Compare September 10, 2024 22:01
This patch makes the parser allow additional tags in <select> besides
<option>, <optgroup>, and <hr>, mostly by removing the "in select" and
"in select in table" parser modes.

In order to replicate the behavior where opening a <select> tag within
another open <select> tag inserts a </select> close tag, a traversal
through the stack of open elements was added which I borrowed from the
<button> part of the parser.

This will need test changes to be implemented in html5lib.

Fixes whatwg#10310
@josepharhar josepharhar force-pushed the selectcomplete branch 2 times, most recently from 46cddc3 to 50bf192 Compare September 12, 2024 21:00
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 found two more small issues, but overall this looks good. In the future I'd prefer the occasional rebase and force push over merge commits. It feels very uncertain whether these 179 commits once squashed will have unintended consequences. Hopefully there are none.

@josepharhar I suggest you prepare this PR for landing, superseding the others. The commit message should explain the change and cause the other PRs to get closed.

@smaug---- any more comments from your side?

@domenic @domfarolino are you both happy with the state of this?

<dt><span data-x="concept-element-content-model">Content model</span>:</dt>
<dd><span>Phrasing content</span>, but there must be no <span>interactive content</span>
descendant and no descendant with the <code data-x="attr-tabindex">tabindex</code> attribute
specified.</dd>
specified. If the element is the first child of a <code>select</code> element, then it may also
have zero or one <code>selectedcontent</code> element.</dd>
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 this is ambiguous with respect to whether this is allowed as child or descendant and how this relates to phrasing content. Maybe @zcorpan has ideas on how to best phrase this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added "descendant" to try making it less ambiguous.

Choose a reason for hiding this comment

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

Similar to the area element, the following is more preferable.

4.10.17 The selectedcontent element
Categories:
    Phrasing content.

Contexts in which this element can be used:
    Where phrasing content is expected, but only if there is, in ancestor, button element which is a child of a select element.

source Outdated
Comment on lines 55103 to 55106
descendant of a <code>datalist</code> element: Zero or more <span><code>option</code> element
inner content elements</span>.</dd>
<dd>If the element has no <code data-x="attr-option-label">label</code> attribute and is a
descendant of a <code>datalist</code> element: <span data-x="text content">Text</span>.</dd>
Copy link
Member

Choose a reason for hiding this comment

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

Above we state it can only be a child of a datalist element (conformance-wise), so this seems incorrect.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I changed it from descendant to child here and above for the datalist cases

@annevk annevk marked this pull request as ready for review June 11, 2025 13:40
@annevk annevk added addition/proposal New features or enhancements topic: forms topic: select The <select> element labels Jun 11, 2025
@josepharhar josepharhar changed the title Complete draft spec for customizable <select> Define customizable <select> Jun 11, 2025
@josepharhar
Copy link
Contributor Author

I suggest you prepare this PR for landing, superseding the others. The commit message should explain the change and cause the other PRs to get closed.

Done, thanks!

<dd>If the element has no <code data-x="attr-option-label">label</code> attribute and is a child
of a <code>datalist</code> element: <span data-x="text content">Text</span>.</dd>
child of a <code>datalist</code> element: Zero or more <span><code>option</code> element
inner content elements</span>.</dd>

Choose a reason for hiding this comment

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

The following is conformance?

<label> Animal:<input name=animal list=animals></label>
<datalist id=animals>
 <label>or select from the list:
  <select name=animal>
   <option><img src="cat.jpg" alt="cat"></option>
   <option><div>dog<br><small>(but except child dog)</small></div></option>
  </select>
 </label>
</datalist>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The option element is not a child of a datalist element, so it falls into the "zero or more option element inner content elements" case, so it's allowed to have the child img and div in your example. Does that answer your question?

Choose a reason for hiding this comment

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

When such option element is displayed as suggestion by datalist element, how is it rendered?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addition/proposal New features or enhancements topic: forms topic: select The <select> element
7 participants