fit-textarea icon indicating copy to clipboard operation
fit-textarea copied to clipboard

No longer possible to set a maximum height?

Open kevinrenskers opened this issue 3 years ago • 10 comments

After updating to v3, setting a max-height on the textarea no longer has an effect. Is there another way to limit how tall it can grow?

kevinrenskers avatar Mar 29 '21 12:03 kevinrenskers

Not sure why fit-textarea now uses min-height instead of just height 🤔

kevinrenskers avatar Mar 29 '21 12:03 kevinrenskers

Not sure why fit-textarea now uses min-height instead of just height 🤔

https://github.com/fregante/fit-textarea/issues/9

blindssuck

Is there another way to limit how tall it can grow?

Honestly I don't know how/if both methods can be supported

fregante avatar Mar 31 '21 04:03 fregante

so to fix this I should probably use min-height or the rows attribute instead

I wonder if using the rows attribute would allow both scenarios? So manual resizing and still able to set a max-height.

For now I'm just pinning to v2.x.

kevinrenskers avatar Apr 03 '21 20:04 kevinrenskers

Interesting… I think the reason why I never tried that is because:

  • the measurement I get is in pixels
  • the line height varies so it needs to be evaluated as well

Since v3 changed how it’s measured altogether (to a more efficient version) maybe I can reliably find the number of rows. Bonus would probably be that #2 would be natively supported

fregante avatar Apr 03 '21 20:04 fregante

Create a hidden textarea using the same style, remove all padding, set rows to 1, and measure size? 🤔

kevinrenskers avatar Apr 03 '21 20:04 kevinrenskers

Maybe, if there’s no rounding. I hope that a whole other textarea isn’t necessary because v3 is already a lot more complex than v2 since it already clones the textarea instead of resizing it twice for every character

fregante avatar Apr 03 '21 21:04 fregante

I too would like to set a maximum height. What if we took that as a JavaScript argument in fit-textarea (or check a data- attribute, or something equivalent to that)?

leafac avatar Jun 28 '21 16:06 leafac

Honestly I don't know how/if both methods can be supported

As a stopgap solution, how about detecting if the textarea has explicitly been made non-resizable?

textarea.style.resize === 'none' || textarea.style.resize === 'horizontal' // use height instead of min-height

Might be useful to allow overriding this, like with a data- attribute as suggested above.

cheap-glitch avatar Jul 22 '22 07:07 cheap-glitch

maybe I can reliably find the number of rows

Isn't it as "simple" as textarea.scrollHeight / line height?

The main headache would be to compute the line height in pixels since it can have a bunch of different values and units.


Or maybe switch to an (almost) pure-CSS solution: https://css-tricks.com/the-cleanest-trick-for-autogrowing-textareas Does not work with manual resizing though…

cheap-glitch avatar Jul 22 '22 09:07 cheap-glitch

switch to an (almost) pure-CSS solution

That's a solution we can link to in the readme, but it wouldn't work on extensions because we don't want to change the DOM.

Moving the rows suggestion to:

  • https://github.com/fregante/fit-textarea/issues/21

fregante avatar Jul 22 '22 09:07 fregante