Re: [csswg-drafts] [css-ui?] Allow `<input>` and `<select>` to be sized by contents (#7552)

The CSS Working Group just discussed `Allow <input> and <select> to be sized by contents`.

<details><summary>The full IRC log of that discussion</summary>
&lt;emilio> topic: Allow &lt;input> and &lt;select> to be sized by contents<br>
&lt;emilio> github: https://github.com/w3c/csswg-drafts/issues/7552<br>
&lt;emilio> lea: so this is related to the &lt;textarea> issue<br>
&lt;emilio> ... this is about sizing the width of &lt;input> and &lt;select> of form controls to match the contents<br>
&lt;emilio> ... it's insanely difficult to do right today<br>
&lt;emilio> ... you need to use a span to measure, or measure scrollHeight if you have overflow, etc<br>
&lt;emilio> ... you don't know how big the icons in date / time / number inputs<br>
&lt;emilio> ... it'd be nice to size these based on their contents<br>
&lt;emilio> ... it'd be elegant if you could just say "width: fit-content" or so<br>
&lt;emilio> ... not sure if that's web-compatible<br>
&lt;emilio> ... a lot of the issues re. &lt;textarea> are not present<br>
&lt;emilio> iank_: not strictly true<br>
&lt;fantasai> emilio: It's not hard to implement<br>
&lt;fantasai> emilio: but there's a lot of different considerations<br>
&lt;fantasai> emilio: for example, the most obvious one after going through this code, is if you odn't want to size it to the size of, for example, autofill suggestions<br>
&lt;fantasai> emilio: if you multiple options to choose from, right now when you hover over the option we preview it<br>
&lt;fantasai> emilio: but we dont' expose that to the page until you actually interact with it<br>
&lt;fantasai> lea: I think it's fine to ignore autofill<br>
&lt;fantasai> lea: never seen a use case that involved passwords<br>
&lt;astearns> ack dbaron<br>
&lt;emilio> dbaron: few thoughts, one of them is "what counts as contents": does placeholder count?<br>
&lt;iank_> q+<br>
&lt;emilio> ... one of the other things you might run into is that for text inputs and you wanna resize as people type you might find the performance of it to be suboptimal<br>
&lt;emilio> ... and that's gonna be a little unpleasant<br>
&lt;astearns> ack iank_<br>
&lt;emilio> ... but I guess people will deal with it if that's what they want<br>
&lt;lea> q+ wrt placeholders<br>
&lt;emilio> iank_: this has the same issue as textarea<br>
&lt;emilio> ... where min/max-content are used directly within the flexbox algorithm<br>
&lt;astearns> ack wrt<br>
&lt;astearns> ack place<br>
&lt;emilio> ... I don't think we can ship anything that changes min-content in these<br>
&lt;astearns> qq+ lea<br>
&lt;emilio> q+<br>
&lt;emilio> iank_: sounds like what emilio implemented yesterday would've changed all of those<br>
&lt;emilio> fantasai: you mean the automatic minimum size?<br>
&lt;astearns> ack fantasai<br>
&lt;Zakim> fantasai, you wanted to ask if it's min-content or the automatic minimum size<br>
&lt;emilio> iank_: also the content size if you use flex-basis: content<br>
&lt;emilio> ... also somewhere else<br>
&lt;emilio> fantasai: I think we could say that the automatic minimum size is whatever size we currently get from html attributes<br>
&lt;emilio> ... but if you use min-width: 0 then you won't be using these<br>
&lt;emilio> s/these/ams<br>
&lt;emilio> ... and then width: max-content to remove the influence of automatic preferred sizes<br>
&lt;emilio> ... and these are both things that you need to do and shouldn't cause a compat issue<br>
&lt;lea> q+ you cannot use min-width: 0; with this, as that would make the input tiny when you delete all content.<br>
&lt;emilio> fantasai: I'm proposing changing the meaning of max-content<br>
&lt;emilio> ... so there's a preferred size<br>
&lt;emilio> ... currently entering flexbox via ams and automatic preferred size<br>
&lt;emilio> ... these are tied to keywords, `min-width: auto`, etc<br>
&lt;fantasai> emilio: but in terms of actual behavior changes<br>
&lt;fantasai> emilio: basically, how do you change the min- or max-content<br>
&lt;fantasai> emilio: what I'm imagining you're saying is, make this change to the max-content size<br>
&lt;fantasai> emilio: so max-content on an input follows the content<br>
&lt;fantasai> emilio: but in flexbox either special case and not call it max-content for inputs<br>
&lt;emilio> fantasai: flexbox doesn't use max-content, it works in terms of contributions<br>
&lt;emilio> iank_: it does work in terms of max-content<br>
&lt;emilio> fantasai: it only does if width is auto, right?<br>
&lt;emilio> iank_: so to opt into this you'd need to change min-width and flex size<br>
&lt;emilio> fantasai: because of ams is tied to this you need to remove it in min-width and so<br>
&lt;emilio> iank_: I agree it'd work but I don't think that'd be a great solution, we already have compat issues with &lt;input> using min-content and stuff like that<br>
&lt;fantasai> emilio: so you're proposing for auto size to be as-is<br>
&lt;fantasai> emilio: and split max-content from preferred size<br>
&lt;fantasai> emilio: which right now are the same<br>
&lt;fantasai> emilio: I'm not a huge fan of adding more intrinsic width types, but maybe it's not too much of a pain<br>
&lt;emilio> iank_: when we were changing the min-width/height: auto behavior, we found that lots of people that set min/max-width: 0<br>
&lt;emilio> ... also common to use flex: 1 1 0 and so<br>
&lt;lea> q?<br>
&lt;dholbert> s#min/max-width:0#min-width/min-height#<br>
&lt;emilio> ... and there you'd change a lot of stuff, seems scary<br>
&lt;astearns> ack lea<br>
&lt;Zakim> lea, you wanted to react to placeholders<br>
&lt;emilio> lea: Wanted to say that placeholders should be considered for calculating the width<br>
&lt;emilio> ... it's implemented as shadow dom descendant<br>
&lt;emilio> ... but also what if we say that this only works if min-width is >0<br>
&lt;TabAtkins> Also very hesitant to override any of the existing content size keywords for this, but am happy to have a new keyword (or two?)<br>
&lt;emilio> ... in most cases you do need to specify min-width of zero<br>
&lt;emilio> ... it's user-hostile to not have that<br>
&lt;iank_> q+<br>
&lt;emilio> fantasai: it's user-hostile to do that ~everywhere<br>
&lt;emilio> ... but we can't do that because it'd be discontiguous<br>
&lt;emilio> nous*<br>
&lt;emilio> fantasai: we could introduce a new max-content-no-i-really-mean-it<br>
&lt;emilio> ... but I'd rather avoid that<br>
&lt;bkardell_> this-is-my-final-answer-max-content<br>
&lt;emilio> TabAtkins: I'd rather do that, I share iank_'s concerns<br>
&lt;astearns> ack emilio<br>
&lt;fantasai> emilio: for select in particular, I don't think it's so problematic<br>
&lt;fantasai> emilio: because it's almost never empty by default<br>
&lt;fantasai> emilio: but for input it seems very sketchy<br>
&lt;dholbert> `max-form-content` or `max-field-content`?<br>
&lt;fantasai> emilio: I also recall Firefox, in terms of select intrinsic sizing<br>
&lt;TabAtkins> oooh yeah i like dholbert's ideas<br>
&lt;fantasai> emilio: because we actually consider the option styles<br>
&lt;fantasai> emilio: I fixed that<br>
&lt;TabAtkins> since these keywords won't mean anything for non-form controls<br>
&lt;fantasai> emilio: it was not an easy change<br>
&lt;astearns> ack iank_<br>
&lt;TabAtkins> (we'll just define them to resolve to min-content or something)<br>
&lt;emilio> iank_: re. placeholder I'm not convinced that it's feasible because we remove the placeholder from the dom when the field is focused<br>
&lt;emilio> ... so you don't want the input to shrink down<br>
&lt;lea> q?<br>
&lt;lea> q+<br>
&lt;emilio> ... when looking into textarea, people let the placeholder overflow sometimes etc<br>
&lt;emilio> ... there's something to consider<br>
&lt;emilio> ... for &lt;select> I think the real usecase it's a different min/max-content algorithm<br>
&lt;emilio> ... all browsers match the current behavior of longest option<br>
&lt;astearns> ack lea<br>
&lt;emilio> ... so you really want a different intrinsic sizing algorithm<br>
&lt;emilio> lea: you say that you remove the placeholder from the dom when you focus<br>
&lt;emilio> ... but it's still visible<br>
&lt;emilio> iank_: when you actually enter content<br>
&lt;emilio> lea: yeah but then you want the input to be sized to the content<br>
&lt;emilio> iank_: I don't think that's what users would expect<br>
&lt;emilio> bramus: I think I agree<br>
&lt;emilio> ... if you have a placeholder with your name then it'd snap<br>
&lt;emilio> lea: in such a form then you wouldn't use this feature<br>
&lt;emilio> ... also you'd define the placeholders with that in mind<br>
&lt;emilio> bramus: but if you have a long place-holder then...<br>
&lt;emilio> lea: that's what min-width is for<br>
&lt;astearns> this is a much different use of an input that was considering<br>
&lt;astearns> s/was/I was/<br>
&lt;emilio> iank_: I think then people wouldn't consider the placeholder and it might get cropped<br>
&lt;emilio> q+<br>
&lt;emilio> lea: they can always use min-width<br>
&lt;emilio> ... for other use cases it's weird to have so much space around your control<br>
&lt;astearns> ack emilio<br>
&lt;dholbert> q+<br>
&lt;fantasai> emilio: I agree that you should be able to use something like input:not(:placeholder-shown) { min-width: .. } and it will be discontinuous when you start hiding it<br>
&lt;fantasai> emilio: in FF we don't remove the placeholder from the DOM, we just hide it with visibility:hidden<br>
&lt;fantasai> emilio: so the min-width of the input is the width of the placeholder<br>
&lt;fantasai> emilio: it is implementable, but ...<br>
&lt;fantasai> iank_: we might have some of ours out-of-flow so they don't contribute to baselines or something like that<br>
&lt;fantasai> emilio: it woudl be great to be interoperable on how we impleemtnt these as well<br>
&lt;fantasai> iank_: this is why I wanted to focus on textarea<br>
&lt;fantasai> iank_: developer need is very clear<br>
&lt;fantasai> iank_: Ideally, we'd standardize on internal structures so we can get exact correct thing<br>
&lt;fantasai> emilio: regarding select, agree that it's effectively a different intrinsic sizing algorithm<br>
&lt;fantasai> emilio: the current one, max-content and new one can be min-content<br>
&lt;fantasai> emilio: it's not amazing, it can be useful<br>
&lt;fantasai> emilio: I was a bit skeptical about this until Lea showed me some slides<br>
&lt;fantasai> emilio: I agree that just changing the meaning of min- or max-content might not be great<br>
&lt;fantasai> emilio: maybe a new property like form-intrinsic-size: legacy ?<br>
&lt;fantasai> emilio: and a new keyword?<br>
&lt;fantasai> emilio: that could work<br>
&lt;fantasai> emilio: and could also work for textarea sizing<br>
&lt;fantasai> emilio: change it so it makes sense<br>
&lt;fantasai> iank_: I agree that would be a nice thing<br>
&lt;fantasai> iank_: my only concern then is, doesn't allow us to ???<br>
&lt;fantasai> iank_: it doesn't allow us to do this in a piecemeal fashion, we have to get everything correct once<br>
&lt;fantasai> iank_: which is a big undertaking<br>
&lt;fantasai> s/once/at once/<br>
&lt;fantasai> emilio: on the flip side, you end up adding one property instead of one per element<br>
&lt;fantasai> emilio: and it has a name that may make more sense<br>
&lt;fantasai> emilio: and not specific for this particular kind of element<br>
&lt;fantasai> emilio: but I agree<br>
&lt;fantasai> iank_: that's why with textarea one I really focused on changing how you multiply lh unit nternally<br>
&lt;fantasai> iank_: but I see what you're saying<br>
&lt;emilio> fantasai: we have an intrinsic-sizing property<br>
&lt;emilio> ... which was intended to fix some of the problems with the way we calculate intrinsic sizing<br>
&lt;emilio> ... so we have a place to put it<br>
&lt;fantasai> https://www.w3.org/TR/css-sizing-4/#intrinsic-contribution-override<br>
&lt;emilio> min-intrinsic-sizing<br>
&lt;emilio> ... names are not amazing, suggestions welcome<br>
&lt;emilio> ... this was about the compressible stuff<br>
&lt;emilio> ... so the reason why everybody puts min-width: 0 on everything is because of this<br>
&lt;astearns> ack dholbert<br>
&lt;emilio> dholbert: two thoughts: first one is that if we have a unified keyword / property for input and textarea<br>
&lt;emilio> ... you might end up with a textarea sizing the line greedily<br>
&lt;emilio> ... sort of the fit-content for textarea vs. max-content with single-line input<br>
&lt;emilio> ... we might need to be a bit careful there<br>
&lt;emilio> ... the first screenshot shows a &lt;select>-like input, but less convinced about &lt;input><br>
&lt;emilio> ... would be good to collect the use cases for these<br>
&lt;emilio> ... willing to believe there are good use cases though the one on the issue seemed a bit abstract<br>
&lt;emilio> iank_: if I had to rank what devs would use<br>
&lt;emilio> ... auto-expanding textarea is the most common I've seen. I agree &lt;select> is probably common as well, but I haven't seen many auto-growing &lt;input><br>
&lt;emilio> bramus: I've seen those in settings-like pages, like newsletter subscription, with a paragraph with two or three text-fields inside<br>
&lt;emilio> astearns: should we go back to the issue, add examples, possible ways of specifying this<br>
&lt;emilio> *?<br>
</details>


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


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

Received on Tuesday, 2 August 2022 20:50:50 UTC