Skip to content
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

innerText getter impact of customizable select #11017

Open
zcorpan opened this issue Feb 11, 2025 · 3 comments
Open

innerText getter impact of customizable select #11017

zcorpan opened this issue Feb 11, 2025 · 3 comments
Labels
topic: select The <select> element

Comments

@zcorpan
Copy link
Member

zcorpan commented Feb 11, 2025

What is the issue with the HTML Standard?

https://html.spec.whatwg.org/#dom-innertext says

  1. If node is not being rendered, then return items. For the purpose of this step, the following elements must act as described if the computed value of the 'display' property is not 'none':

    1. select elements have an associated non-replaced inline CSS box whose child boxes include only those of optgroup and option element child nodes;

    2. optgroup elements have an associated non-replaced block-level CSS box whose child boxes include only those of option element child nodes; and

    3. option element have an associated non-replaced block-level CSS box whose child boxes are as normal for non-replaced block-level CSS boxes.

Given <select><div><option>foo</option></div></select>, select.innerText would be the empty string (because there is no option child node), which is different from old select parsing (where the div is dropped).

Relevant tests: https://wpt.fyi/results/html/dom/elements/the-innertext-and-outertext-properties/getter.html?label=master&label=experimental&aligned&q=innertext

Also currently innerText per spec would drop text outside of optgroup/option in select. (e.g. <select>foo</select> per the current spec gives the empty string.)

I suppose the options are:

  1. tweak it to include descendant optgroup/options, not just children
  2. remove the special casing
  3. keep the innerText spec as-is

I think (1) seems safest in terms of web compat, but I don't know if there are strong web compat constraints here.

Also see:

cc @josepharhar

@zcorpan zcorpan added the topic: select The <select> element label Feb 11, 2025
@myakura
Copy link

myakura commented Feb 11, 2025

I think (1) seems safest in terms of web compat, but I don't know if there are strong web compat constraints here.

There was a report on twitter around Chrome introduced the select parser change that broke option.innerText being blank:

I should do this we had some old code could be bad… we used innerText to get the text content of option elements within a select tag. It was working well and then it started giving us back blank text values… it’s unclear to me if we broke this or it was the result of something changing in chrome… we fixed our side by using innerHTML instead…

https://x.com/taf2/status/1859935811330060576

@josepharhar
Copy link
Contributor

I implemented option 1 in chrome already: https://chromium-review.googlesource.com/c/chromium/src/+/6173103

I included the changes in the spec PR for the content model here: #10586

Specifically this: 1117978

I can move the commit to another PR if you'd like.

@zcorpan
Copy link
Member Author

zcorpan commented Feb 12, 2025

@josepharhar ah, I had missed that. I'm ok with it being in the same PR, it can be marked as also fixing this bug when merging.

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

No branches or pull requests

3 participants