Skip to content
This repository has been archived by the owner on Jun 30, 2024. It is now read-only.

Issue when textarea reaches the end of the window height size #82

Open
SunnyAureliusRichard opened this issue Mar 3, 2022 · 16 comments · May be fixed by #85
Open

Issue when textarea reaches the end of the window height size #82

SunnyAureliusRichard opened this issue Mar 3, 2022 · 16 comments · May be fixed by #85
Assignees

Comments

@SunnyAureliusRichard
Copy link

Greetings!

There's an issue with the view height flipping between where the cursor is, and the top of the page.

Demo available @ https://codesandbox.io/s/tailwind-css-and-react-forked-qhfgif?file=/src/components/Homepage.js

To reproduce, do the same as in the gif:
react-expanding-textarea

PS: in the README.md file for the label it should be htmlFor="my-textarea" --- not for="my-textarea"

To fix, this line has to be commented out el.style.height = '0'

@rpearce
Copy link
Owner

rpearce commented Mar 3, 2022

Thanks for reporting this and providing a demo — that is very helpful.

Commenting out that line prevents the auto-resizing from working.

imagen

I'll need to think on this one... Other ideas are welcome, as well.

@rpearce rpearce self-assigned this Mar 3, 2022
@SunnyAureliusRichard
Copy link
Author

It works fine for me, what's the issue?

@rpearce
Copy link
Owner

rpearce commented Mar 4, 2022

In the screenshot above, the textarea does not resize with the content, and that is what this library is supposed to do.

If you run the Storybook examples (npm start) in the project and comment that line out, this quickly becomes apparent:

The minimalist text area does not resize imagen
The regular text area does not resize imagen

There are 7 examples, and none of them function.

@SunnyAureliusRichard
Copy link
Author

The solution might be to create another textarea that is hidden, with the same text as the "real" textarea, that can be used to fetch the height the expanding textarea should set to

see: https://stackoverflow.com/a/56914733/1204843

@rpearce
Copy link
Owner

rpearce commented Mar 6, 2022

I'm aware of this technique, but I'm personally not a fan of having duplicate markup and content like that in the browser for a few reasons.

I will try to find a different solution. Thanks for your patience

@rpearce
Copy link
Owner

rpearce commented Mar 12, 2022

@SunnyAureliusRichard If you get a moment, are you able to evaluate #85? If I don't hear back within a few days, I'll ship it out and follow back up here.

@SunnyAureliusRichard
Copy link
Author

Hi @rpearce

Thank you for this. It does seem to fix the problem, but it's not as smooth as it could be.

Here is "Style changes" story with the line "height = 0" commented out, and without the fix you've suggested. Notice that when I add more lines, the page continues to scroll down.
react-expanding-textarea-with-height-nonzero

And here is the same story, with the line "height = 0" left in, and with the fix you've suggested. Notice that when I add more lines, the page scrolls up, and only a part of the textarea is visible.
react-expanding-textarea-with-rc

Thanks

@rpearce
Copy link
Owner

rpearce commented Mar 14, 2022

Thanks for taking a look. When I get some time, I'll see if maybe I only do the height = 0 when the value's length is reduced 🤔 . The reason for it is when you remove content, it needs to resize to fit the new size.

@SunnyAureliusRichard
Copy link
Author

I think doing that will result in the same difference between the gifs in the last post. I know why it's important to have height = 0. I don't know an elegant way to fix this either. It's definitely a tricky one.

@templeman15
Copy link

templeman15 commented Oct 29, 2022

Commenting back here as I'm running into the same issue. Any plan to merge in the PR or try the height = 0?

Thank you!

@rpearce
Copy link
Owner

rpearce commented Oct 30, 2022

@templeman15 Both approaches have their own issue (see my note above about that height: 0), and I put this on the side after diving in for a bit and not getting anywhere.

I'll consider this an opportunity to think about it a little more.

@templeman15
Copy link

@rpearce just looping back, I ended up switching to:

react-textarea-autosize

Maybe you could check out what they're doing. Best of luck 👍🏼

@rpearce
Copy link
Owner

rpearce commented Nov 4, 2022

I've spent a couple of nights refactoring this project to find a simpler way.

I need to do way more testing, but I may have just re-implemented this in 729 bytes (minified & gzipped) and also solved this problem in the process (proof of concept).

We'll see how this shakes out! There's a good deal bit to play with. Stay tuned...

@rpearce
Copy link
Owner

rpearce commented Nov 23, 2022

I've got a few too many things going on, and I've paused this update and will get back to it at some point.

@fennick-fox
Copy link

We're encountering this issue, too. Sounds like there might not have been any progress on it, but let us know if you fix this issue!

@rpearce
Copy link
Owner

rpearce commented Mar 18, 2023

It's a pretty tough issue without doing a rewrite. When I was rewriting this, I found I was actually recreating https://github.com/Andarist/react-textarea-autosize

I hate saying this, but it's enough of an issue that I think I'll need to recommend using that library over my own.

I simply don't have time to invest in an already-well-solved problem.


It's not a great answer, but it is one. Are you ok trying out the other library and checking back in here?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants