Closed benwiley4000 closed 4 years ago
There is a related issue which I didn't open a thread for, which is that if the oversized third-party font is loaded asynchronously after the initial React paint, there will be a one-time, permanent height increase in the multiline input the first time it is focused or otherwise re-rendered. This height change turns out to be desirable, so the best solution I could come up with is to make sure that all my font assets are preloaded by the HTML head, so they're available during the first paint. After implementing that change, the only remaining issue was this last-row-height inconsistency.
@benwiley4000 Exciting to see the font customization being stress-tested :).
Current Behavior 😯
Certain fonts, specifically those which take up more vertical space than the expected
line-height
, will cause the autosized height of aTextareaAutosize
to be a bit taller. This is ok, but the property used to compute the height,scrollHeight
, turns out to be inconsistent depending on whether the last row of text input is empty or not. When the last row is empty, the last row takes up the standardline-height
, and if the last row is non-empty, then it assumes the height of the chosen font.Note that the only
font-family
that ships in browsers and will yield this behavior iscursive
, as far as I know. However the issue also comes up with some third-party fonts seen in the wild.Demo of issue (for rows > 3)
Expected Behavior 🤔
The height should be measured as though the last line contains text, and therefore be consistent.
Steps to Reproduce 🕹
Steps:
textarea
instances (shown and hidden) render using an extra-tall font (trycursive
)rowsMin
and observe the difference when adding new empty rows and then adding content to the last rowOr, just check out this Codesandbox: https://codesandbox.io/s/musing-mendeleev-uh3u2
Context 🔦
It's just annoying for text to be moving around while you're typing.
Your Environment 🌎