Andarist / Andarist/react-textarea-autosize

Autosize textarea width support

未关闭
#144 4 条评论 4 个 reaction 已指派 0 人 在 GitHub 查看
enhancement
主要语言
TypeScript
星标
2.4k
派生
247
PR 合并指标
30 天内没有已合并 PR

描述

Hello.

I just thought that it could be neat to have `width` of `textarea` to be also autosizable.
[Proof of concept](https://github.com/kengho/react-textarea-autosize).

I used approach to search for the largest `width` that gives the lowest `textarea.scrollHeight` (since `textarea.scrollWidth` seems not to show correct value (maybe I'm wrong about that)).
```
width => textarea.scrollHeight
1 => 1000
2 => 500
3 => 200
4 => 80
5 => 80
6 => 70 <= answer
7 => 70
8 => 70
9 => 70
```
I couldn't figure out better way that using binary-ish search yet, but maybe there are better ways (I'm sure about that; for example, it could be possible to apply default JS sort using some kind of array emulation, or maybe there are even cleanest ways), and also maybe there are devs that will use this feature even considering higher resources consumption.

Btw, in regular-sized textareas this approach gives acceptable result after 5-10 iterations.

What do you think?

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。