web-components icon indicating copy to clipboard operation
web-components copied to clipboard

[text-area] Min/max rows attributes/properties

Open yuriy-fix opened this issue 6 years ago • 15 comments

Controlling the minimum and maximum height of the text-area is a common thing. Some DX/UX tests participants were expecting to see attributes for doing that. Should we introduce those or something like min-rows, max-rows that will be standing for height?

yuriy-fix avatar Nov 20 '17 13:11 yuriy-fix

Let’s keep this as an enhancement request for now. Add your ”+1” reaction if you really need this.

jouni avatar Nov 20 '17 13:11 jouni

The current way of controlling this is to use CSS min|max-height for the <vaadin-text-area> element.

vaadin-text-area {
  min-height: 100px;
  max-height: 300px;
}

See live examples: https://vaadin.com/components/vaadin-text-field/html-examples#text-area-demos

jouni avatar Mar 09 '18 13:03 jouni

min-height: 10px; didn't work

lanmaster avatar Oct 21 '20 12:10 lanmaster

@lanmaster do mean that the field does not shrink to 10px? There's an issue about that: vaadin/web-components#1363

jouni avatar Oct 22 '20 15:10 jouni

So take to consideration: https://github.com/vaadin/vaadin-text-field/issues/506

netbeansuser2019 avatar Nov 02 '20 06:11 netbeansuser2019

Let me react to @jouni

There is simple use case as TextArea can be only scroll entirely then you cannot use well prefix and suffix component as it is hard to e.g. place any content into middle in such suffix or prefix, because if it is scrollable than such component ends out of visible area ... so if you need content to be possibly seen to user all the time ... like buttons, advice, status indicator, data indicator, and so on you can not do that for TextArea. So if you needed that you have to add extra wrapping so than there is not reason for suffix and prefix component at all if there is no simple way to adjust that. So if there is not expectation to turn back rows as in previous version Vaadin than I would like to suggest to be possible to turn on just scrolling of "input-area".

netbeansuser2019 avatar Nov 18 '20 07:11 netbeansuser2019

Thanks for the use case description, @netbeansuser2019!

To me it seems like that’s a separate topic, whether or not the prefix and suffix elements scroll together with the text content (vs how to control the sizing of <vaadin-text-area>).

If I understood correctly, I think what you are asking is for a way to directly pass the rows attribute to the internal <textarea> element. I don’t think we want to do that, as that exposes the internal implementation details of the component. That said, we could still offer an API to set the height limits as “rows”, for example with min-rows and max-rows attributes. How those would internally work, might be using the rows attribute on the textarea, but might be something else.

As for the other use case (scrolling), that could also be opt-in/out (like you mentioned in vaadin/vaadin-text-field#506 ). Though, I admit that I don’t remember any concrete use cases where you’d want the prefix/suffix element to scroll with the text.

Finally, as a workaround, you can achieve the desired scrolling behavior by using position: sticky;. Note, that it doesn’t work in IE11 or old Edge versions.

<vaadin-text-area>
  <div slot="prefix">Prefix</div>
</vaadin-text-area>

<style>
[slot="prefix"] {
  position: -webkit-sticky;
  position: sticky;
  top: 0;
}
</style>

jouni avatar Nov 18 '20 10:11 jouni

I do not think so it could be fixed by "sticky" in case of "middle".

netbeansuser2019 avatar Dec 03 '20 09:12 netbeansuser2019

Not sure what you mean with ”middle” – can you elaborate?

jouni avatar Dec 03 '20 12:12 jouni

I mean like any icon shown in middle of visible area not in middle of entire scrollable area.

netbeansuser2019 avatar Dec 09 '20 12:12 netbeansuser2019

You mean like this? Screen Shot 2020-12-09 at 14 56 59

That can be done like this:

[slot="prefix"] {
  position: -webkit-sticky;
  position: sticky;
  top: 50%;
  transform: translateY(-50%);
}

jouni avatar Dec 09 '20 12:12 jouni

Firstly this should be possible just from API. If I used your code in https://www.w3schools.com/Css/tryit.asp?filename=trycss_position_sticky so wrapped to DIV as styled as flex and no padding and set fixed size and overflow to scroll that has such two div-s inside such sticky one has never been in middle of visible area with new Edge and even FF, but ends on "the first line".

netbeansuser2019 avatar Dec 09 '20 14:12 netbeansuser2019

Hey, I’m just trying to help, provide a workaround 🤗 Perhaps it should be a built-in feature, but that’s probably not going to happen very soon, so we need to make due with workarounds until then.

I didn’t test this this in all sorts of situations, so there probably are cases where sticky doesn’t work like you’d want it to.

Would be great if you could provide example code. It’s a bit hard to understand the problem you described above.

jouni avatar Dec 09 '20 14:12 jouni

I tried to replicate the case that you described, the best I understood. Feel free to ”remix” the example: https://glitch.com/~peppermint-rambunctious-entree

It does have an issue in Safari, where the sticky prefix element scrolls out of view (inside the text area) when you scroll far enough.

jouni avatar Dec 09 '20 14:12 jouni

Any update on including min-rows / max-rows for a fixed textarea height since the start of this issue back in 2017?

mil3stone avatar Jul 15 '22 12:07 mil3stone

Workaround for Java, assuming there's an internal <textarea> element in light dom:

TextArea textArea = ...
textArea.getElement().executeJs("$0.getElementsByTagName('textarea')[0].setAttribute('rows','1');$0.getElementsByTagName('textarea')[0].style.minHeight = 0;", textArea.getElement());

OlliTietavainenVaadin avatar Sep 19 '23 11:09 OlliTietavainenVaadin