-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Allow <textarea> to size to its contents like <div contenteditable> #6807
Comments
There is non-standard |
A |
That's an interesting idea. I wonder if @whatwg/css thought about automatically resizing |
We've been looking at this problem a little - I wrote up an explainer for an approach we think might work: Expanding
|
A little more detail, since I argued for this in person: Whether a textarea is suitable for auto-expansion or not can depend on how it's used in the UI, which can change based on screen size, etc. This is similar to how something that might be tabs on desktop should be accordion on mobile (and thus, the choice of which is used shouldn't be baked into the markup, but rather be controllable via CSS); it's 100% a layout/styling choice rather than a semantic one, and so should be controllable via CSS (rather than possibly requiring an author who does want it to change based on MQs to set up MQ listeners to manually toggle the attributes in script...). And beyond the raw "can it expand or not", the min/max lines it should be able to expand to is clearly a stylistic choice that can vary based on the surrounding layout context. Secondly, if you have multiple such textareas, there's a good chance you might want them to all work the same way. One style rule is easier than adding attributes to each by hand. So yeah, having these as HTML attributes is good, but they should be presentational hints for a new trio of |
Is the complexity with a CSS-based solution that it has to work across all elements? It's not immediately clear to me we want to introduce new presentational attributes. |
No, it doesn't. While we generally try to define things such that they work across a broad range of elements, we do have element-specific properties (a bunch inherited from SVG, mostly). An explicit
Well, at least |
I guess I'd argue that |
CSSWG resolution:
I think css-ui should have its property definition and a high-level overview, and the HTML specification should define concrete behaviors of each HTML elements. We can start with |
I made a prototype for The content box should include the height of the last empty line even if
|
Google Chrome 119.0.6022.0 canary has an experimental implementation of
Your feedbacks is welcome. |
I'm making an HTML specification patch. My current thought is:
|
This covers: - input element as a text entry widget size attribute is ignored if field-sizing:content - input element as domain-specific widgets (optional) - input element as a file upload control (optional) - select element size attribute is used only for dropdown/listbox switching if field-sizing:content - textarea element cols/rows are ignored if field-sizing:content Issue: whatwg#6807 Issue: w3c/csswg-drafts#7542
Is there any interaction with
Is there a use case for this? Maybe we should just not support it, to avoid having potential interop issues? |
Presumably |
Can you elaborate what you mean by this? The <textarea cols=1 style="width: 100px"> |
It doesn't in WebKit (and maybe not in Chromium therefore), but per the HTML Standard that's a bug: https://html.spec.whatwg.org/#textarea-wrapping-transformation. |
Yeah, same for us, see here |
I filed a separate issue about the spec not reflecting reality here: #9896 |
I don't think so.
As for |
This covers: - input element as a text entry widget size attribute is ignored if field-sizing:content - input element as domain-specific widgets (optional) - input element as a file upload control (optional) - select element size attribute is used only for dropdown/listbox switching if field-sizing:content - textarea element cols/rows are ignored if field-sizing:content Issue: whatwg#6807 Issue: w3c/csswg-drafts#7542
It seems to me block-size for Also see @emilio's concerns with autofill in #9903 (comment) |
There is demand for the other things (designers wanting to shrink-wrap controls quite often). |
This includes tests to confirm size/cols/rows are not presentational hints. Issue: whatwg/html#6807
This includes tests to confirm size/cols/rows are not presentational hints. Issue: whatwg/html#6807
Automatic update from web-platform-tests html: Tests for field-sizing (#44346) This includes tests to confirm size/cols/rows are not presentational hints. Issue: whatwg/html#6807 -- wpt-commits: df6595ec7e75fdf8fb524a039c32a030fc1075e9 wpt-pr: 44346
Automatic update from web-platform-tests html: Tests for field-sizing (#44346) This includes tests to confirm size/cols/rows are not presentational hints. Issue: whatwg/html#6807 -- wpt-commits: df6595ec7e75fdf8fb524a039c32a030fc1075e9 wpt-pr: 44346
Automatic update from web-platform-tests html: Tests for field-sizing (#44346) This includes tests to confirm size/cols/rows are not presentational hints. Issue: whatwg/html#6807 -- wpt-commits: df6595ec7e75fdf8fb524a039c32a030fc1075e9 wpt-pr: 44346 UltraBlame original commit: 8e4feaecb790a7e698dd0c2e84cd6d8386c6b13b
This includes tests to confirm size/cols/rows are not presentational hints. Issue: whatwg/html#6807
Automatic update from web-platform-tests html: Tests for field-sizing (#44346) This includes tests to confirm size/cols/rows are not presentational hints. Issue: whatwg/html#6807 -- wpt-commits: df6595ec7e75fdf8fb524a039c32a030fc1075e9 wpt-pr: 44346 UltraBlame original commit: 8e4feaecb790a7e698dd0c2e84cd6d8386c6b13b
This includes tests to confirm size/cols/rows are not presentational hints. Issue: whatwg/html#6807
plaintext-only would work smoothly on Chrome, but in Firefox or older browsers, the div might be disabled. The only solution to address this issue is by implementing JavaScript. This code worked for me
|
Well done for implementing it, it is so nice to cut out of the resize observers and JS we to have to do this. Good Job! Would have been great to treat The bfgeek's proposal was superior because one could specify how many rows to have at least, and then specify it should grow as required. Which I suspect in real website is the most common use case. |
There doesn't seem to be a non-JS way of accepting plantext in an element that resizes to fit the text (like
<div>
does).https://css-tricks.com/auto-growing-inputs-textareas/
Could a layout mode be added to textarea to make it behave like
<div>
?The text was updated successfully, but these errors were encountered: