Re: [csswg-drafts] [selectors] Add pseudo-classes for `<select>` being a drop-down box vs a list box (#7422)

The CSS Working Group just discussed `Pseudo-classes for drop-down vs list box for <select>`.

<details><summary>The full IRC log of that discussion</summary>
&lt;fantasai> Topic: Pseudo-classes for drop-down vs list box for &lt;select><br>
&lt;fantasai> github: https://github.com/w3c/csswg-drafts/issues/7422<br>
&lt;fantasai> zcorpan: Proposed pseudo-class for &lt;select> elements<br>
&lt;fantasai> zcorpan: it's implemented in both Gecko and Chromium for their UA styles, under a vendor prefix<br>
&lt;fantasai> zcorpan: WebKit doesn't implement the pseudo-class, instead uses attribute selectors<br>
&lt;fantasai> zcorpan: and they have some bugs because of that, because hard to get the details right<br>
&lt;fantasai> zcorpan: so I think there's agreement in the issue that we should have this pseudo-class<br>
&lt;fantasai> zcorpan: and just need to settle thenaming<br>
&lt;emilio> q+<br>
&lt;zcorpan> :select-with-dropdown and :select-no-dropdown<br>
&lt;fantasai> zcorpan: :select-with-drop-down and :select-no-dropdown<br>
&lt;heycam> the WebKit UA style rules: https://searchfox.org/wubkat/rev/0c40ba62b482511fe03646f1d4982efd727475dd/Source/WebCore/css/html.css#1078-1092<br>
&lt;astearns> ack fantasai<br>
&lt;emilio> fantasai: haven't read the issue, was the bug in webkit about parsing the size attribute as int?<br>
&lt;fantasai> zcorpan: It's parsing the size attribute correctly, the UA style sheet has an approximation of what the HTML results are<br>
&lt;fantasai> zcorpan: so some edge cases will get wrong UA styles<br>
&lt;fantasai> zcorpan: get a drop-down widget, but UA style thinks it should be a list box<br>
&lt;fantasai> zcorpan: so a bit of a mismatch<br>
&lt;emilio> fantasai: asking because it's the way the ua parses integers not being replicatable in css<br>
&lt;emilio> ... maybe we want to introduce a way of selecting based on whether the attr is parsed correctly as an integer<br>
&lt;emilio> ... that's been requested and more generally useful<br>
&lt;heycam> q+<br>
&lt;fantasai> zcorpan: I guess it would be possible<br>
&lt;emilio> zcorpan: guess it would be possible<br>
&lt;fantasai> zcorpan: complication because HTML has multiple number attributes<br>
&lt;fantasai> zcorpan: It has integers and signed integers and floats<br>
&lt;fantasai> zcorpan: I guess CSS could have those as well<br>
&lt;fantasai> zcorpan: but CSS numbers are normally parsed differently from HTML numbers<br>
&lt;emilio> fantasai: we could make it the same or have a flag<br>
&lt;dbaron> "The display size of a select element is the result of applying the rules for parsing non-negative integers to the value of element's size attribute, if it has one and parsing it is successful. If applying those rules to the attribute's value is not successful, or if the size attribute is absent, then the element's display size is 4 if the element's multiple content attribute is present, and 1 otherwise." is the relevant quote from<br>
&lt;dbaron> https://html.spec.whatwg.org/multipage/#concept-select-size<br>
&lt;fantasai> zcorpan: Still seems more difficult to use as Web developer compared to pseudo-class<br>
&lt;fantasai> zcorpan: there's also the multiple attribute<br>
&lt;astearns> ack emilio<br>
&lt;fantasai> emilio: I don't think it's a bad idea, but do we really need 2 pseudo-classes instead of one?<br>
&lt;fantasai> emilio: would rather have single one, they're mutual exclusive<br>
&lt;fantasai> emilio: assuming it's &lt;select>-specific<br>
&lt;fantasai> emilio: using select:listbox and select:not(listbox) would be nicer<br>
&lt;fantasai> zcorpan: I think that's an okay outcome, biggest difference is you need to include a type selector to match the :not() state, whereas with pseudo-classes can only use the pseudo-classes<br>
&lt;emilio> fantasai: we need to consider that we keep adding pseudo-classes<br>
&lt;emilio> ... if we don't really need a pseudo-class<br>
&lt;emilio> ... it's better not to have it<br>
&lt;emilio> ... so that there's less for people to memorize<br>
&lt;emilio> q+<br>
&lt;emilio> zcorpan: agreed<br>
&lt;astearns> ack heycam<br>
&lt;emilio> fantasai: if we can do this with integer parsing and it's not too tricky maybe that's a better way around it<br>
&lt;TabAtkins> In particular, if this is &lt;select>-specific, then its name should be pretty &lt;select>-specific, not generic. Probably means it needs a "select" in the name. But then it's just awkward to have to specify select again, like `select:not(:select-with-dropdown)`<br>
&lt;fantasai> heycam: I'm not strongly against adding pseudo-classes, but wondering if really that useful to expose to authors<br>
&lt;fantasai> heycam: if WebKit wants to fix compat issues, they can have an internal pseudo-class like other engines<br>
&lt;fantasai> heycam: but for authors, thinking whether they are using listbox or dropdown, is something they know ahead of time<br>
&lt;fantasai> heycam: I think it's rare for pages to switch between the two, so don't know how useful it is for authors to have different styles depending on this<br>
&lt;fantasai> heycam: or need to rely on the flexibility of how HTML parses these attributes, vs knowing through the DOM already<br>
&lt;fantasai> &lt;fantasai> +1<br>
&lt;fantasai> zcorpan: for cases where dev controls both markup and CSS, but that's not always the case<br>
&lt;fantasai> zcorpan: maybe you're writing a stylesheet for a design system, want to apply to all WordPress pages<br>
&lt;fantasai> zcorpan: you don't know what HTML they will use<br>
&lt;astearns> ack emilio<br>
&lt;fantasai> zcorpan: so that's why pseudo-class makes sense<br>
&lt;fantasai> emilio: Was going to make similar comment to heycame<br>
&lt;fantasai> emilio: we should encourage use of multiple attribute, it's easy to write selectors for that<br>
&lt;fantasai> emilio: rather than relying on parsing of size attribute<br>
&lt;fantasai> emilio: if you're making design system, ask them to use that<br>
&lt;fantasai> emilio: but I'm on the edge on whether it's worth having a pseudo-class for this or not<br>
&lt;fantasai> zcorpan: multiple is a semantic difference<br>
&lt;fantasai> emilio: sorry, yes, you're riht<br>
&lt;fantasai> s/riht/right/<br>
&lt;fantasai> zcorpan: you can have a listbox that's not multiple<br>
&lt;emilio> fantasai: doesn't seem to me like the selector for this would be that difficult if we had number parsing<br>
&lt;emilio> ... is [multiple] plus size parsing as an integer >1<br>
&lt;emilio> ... the details of how to parse invalid size attributes is a concern for implementors but not authors<br>
&lt;fantasai> zcorpan: type out the two selectors?<br>
&lt;TabAtkins> `select[size > 1], select[multiple]`<br>
&lt;emilio> ... people usually don't write junk in their size attribute<br>
&lt;emilio> `select:is([multiple], [size]:not([size="1"]))` is probably close enough in practice today<br>
&lt;fantasai> `select:not([size>1],[multiple])`<br>
&lt;astearns> ack dbaron<br>
&lt;fantasai> dbaron: One, I tend to agree that if you're building a design system, you probably want these sorts of things<br>
&lt;fantasai> dbaron: I think part of the reason we don't see much demand is that select is so hard to style, don't run into this problem much<br>
&lt;fantasai> dbaron: if styling select worked more reliably, they would want on this more<br>
&lt;fremy> +1 to what dbaron just said, styling select is a pain<br>
&lt;fantasai> dbaron: Quoted HTML, which defines the display size of a select element<br>
&lt;fantasai> dbaron: condition for a combobox vs listbox is display size being equal to 1 or not<br>
&lt;fantasai> zcorpan: or multiple attribute being present or not<br>
&lt;fantasai> dbaron: There's a few reasons the selectors above are wrong<br>
&lt;fantasai> dbaron: one is that you need to test for size being zero<br>
&lt;fantasai> dbaron: because HTML applies rules for non-negative integers<br>
&lt;fantasai> dbaron: you want a valid size that is zero or 2 or more<br>
&lt;fantasai> dbaron: or the multiple attribute<br>
&lt;astearns> q?<br>
&lt;fantasai> dbaron: it's doable if you had HTML non-negative integer parsing<br>
&lt;fantasai> dbaron: but might be worth having this pseudo-selector anyway<br>
&lt;fantasai> TabAtkins: fantasai's point was that dealing with invalid things is the sort of things that UA needs to care about, but page author doesn't<br>
&lt;fantasai> TabAtkins: if they're putting random trashi in their size attribute, that's their problem<br>
&lt;heycam> +1 to if we do have a way to do this, would rather a specific pseudo-class rather than a general integer parsing selector<br>
&lt;fantasai> TabAtkins: but HTML UA needs to deal with all kinds of random trash<br>
&lt;fantasai> dbaron: As you go further down the stack to style sheets meant to apply to more and more pages, get closer to needing to match implementation<br>
&lt;fantasai> dbaron: bootstrap might get bugs on this<br>
&lt;fantasai> TabAtkins: Bootstrap can say, "don't write random trash in your size attribute and this will work correctly"<br>
&lt;fantasai> TabAtkins: if we were stricter in parsing this earlier we wouldn't have this problem for UAs<br>
&lt;fantasai> TabAtkins: but even widely-used library, nobody needs to deal with this much trash<br>
&lt;fantasai> TabAtkins: put a number here, and it works. Put a non-number here and it'll not work<br>
&lt;fantasai> fremy: Authors shouldn't have to read the spec to figure out the conditions<br>
&lt;fantasai> fremy: of course they can copy some weird code, but not very understandable<br>
&lt;fantasai> fremy: you will copy and paste it, but not clear what it does at first sight<br>
&lt;fantasai> fremy: if already implemented in engines, have this pseudo-class<br>
&lt;fantasai> fremy: that sounds useful so why not<br>
&lt;fantasai> fremy: why are we wasting time discussing if it's just removing a prefix in the code, seems silly<br>
&lt;astearns> ack fantasai<br>
&lt;fantasai> astearns: We started with what we called a pseudo-class, and now discussing maybe not having pseudo-class<br>
&lt;fantasai> astearns: with arguments presented so far, anyone convinced we should have it?<br>
&lt;fantasai> heycam: me<br>
&lt;fantasai> astearns: Should we try to resolve to add pseudo-class?<br>
&lt;fantasai> fantasai: I'd like to hear from Rachel Andrew and emeyer<br>
&lt;fantasai> fantasai: if they are like, "Yes, we should definitely have this!" then great<br>
&lt;emilio> FWIW this is how Gecko used to implement this with attribute selectors: https://hg.mozilla.org/mozilla-central/rev/13062d9979d254481851c0f8c9d9e608d91f6ae3<br>
&lt;fantasai> fantasai: If not, I'm skeptical<br>
&lt;rego_> there has been a lot of research about styling select in openUI, does anyone know if this topic was discussed?<br>
&lt;fantasai> emeyer: It's hard for me to say, a pseudo-class mostly feels correct here, but fantasai is correct, we have so many pseudo-classes now<br>
&lt;fantasai> emeyer: even more than I realized until recently<br>
&lt;fantasai> emeyer: So I'm not sure I'm 100% convinced that it's best<br>
&lt;fantasai> emeyer: Some way of doing this is good<br>
&lt;fantasai> emeyer: but whether it should be a pseudo-class or ???<br>
&lt;fantasai> fantasai: We would add number-based attribute selectors, and you would make a selector<br>
&lt;fantasai> astearns: It would be a copy-paste incantation<br>
&lt;fantasai> fantasai: still have to do that if it's a pseudo-classs!<br>
&lt;emilio> Another interesting edge case is `size=""`<br>
&lt;heycam> emilio, similar but not exactly the same as the current WebKit UA style rule selectors<br>
&lt;fantasai> TabAtkins: Who is asking for this? In the UA is one thing, but do other people need it?<br>
&lt;heycam> emilio, yes that is exactly the difference<br>
&lt;fantasai> zcorpan: reset stylesheets use it<br>
&lt;emilio> q+<br>
&lt;fantasai> zcorpan: incorrectly, usually<br>
&lt;fantasai> fantasai: They are copy-pasted, so they can write a proper selector<br>
&lt;astearns> ack emilio<br>
&lt;fantasai> zcorpan: but used in lots of pages, should get all the cases correct<br>
&lt;fremy> https://github.com/sansotmon/asistencia-salvarte/blob/50dde64556294e8e42dbb2f7950f1b9c078ebef7/web/core/themes/olivero/css/components/form-select.css<br>
&lt;TabAtkins> Importantly - if they're not getting it right, *is this causing problems for people*?<br>
&lt;fantasai> emilio: empty size attribute is another case<br>
&lt;fantasai> emilio: also slightly more efficient to do a pseudo-class<br>
&lt;fremy> ```[dir="ltr"] select[multiple] { padding-left: 9px }```<br>
&lt;TabAtkins> Are they getting bugs and ignoring them because parsing numbers via CSS is hard? Or are they just not getting bugs?<br>
&lt;fantasai> emilio: pre-parses faster than other random attributes<br>
&lt;fremy> ^ this is wrong, first hit on github<br>
&lt;fantasai> emilio: If ppl feel this is useful, then maybe it's not worth copy-pasting a weird incantation<br>
&lt;rachelandrew> q+<br>
&lt;astearns> ack rachelandrew<br>
&lt;fantasai> rachelandrew: I think in terms of being easier to explain and less error-prone, pseudo-class is good<br>
&lt;fantasai> rachelandrew: but do ppl actually want to do this, is also a valid concern<br>
&lt;fantasai> rachelandrew: if people aren't asking for it<br>
&lt;fantasai> rachelandrew: I like things to be straightforward<br>
&lt;fantasai> rachelandrew: but we also have a lot of pseudo-classes, and have to teach people<br>
&lt;fantasai> rachelandrew: so I don't have a strong feeling, but like emeyer I'm on the fence<br>
&lt;fantasai> astearns: Then what I want to do is to close off the discussion in this meeting, take back to issue, have whatever the actual correct integer and multiple check would be<br>
&lt;fantasai> astearns: so we have something to compare<br>
&lt;fantasai> astearns: and come back to this issue on a telecon<br>
&lt;fantasai> zcorpan: OK<br>
&lt;fantasai> astearns: any other questions on this?<br>
&lt;emilio> fantasai: do we want to add integer attr selectors?<br>
&lt;emilio> ... generally speaking, do we want a proposal for that?<br>
&lt;emilio> astearns: I dont' think we can decide that r/n<br>
&lt;fantasai> astearns: not decide right now<br>
&lt;fremy> select[multiple], select[size] {   height: auto; }<br>
&lt;fremy> in bootstrap<br>
</details>


-- 
GitHub Notification of comment by css-meeting-bot
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/7422#issuecomment-1249567427 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Friday, 16 September 2022 16:35:37 UTC