Open cheap-glitch opened 2 years ago
new ResizeObserver(console.log).observe(document.querySelector('textarea'))
also works on user resizes. Test on this page
Yeah, that's what I use right now but it feels backwards. Since I disable manual resizing anyway, it makes more sense imo to "hook" into fixTextarea
internals.
Should be as simple as textarea.dispatchEvent(new CustomEvent('fit-textarea', {bubble, etc}))
, but what would you use it for?
Use case: I have an auto-fit textarea at the bottom of a page, and I'd like to keep the vertical scroll all the way down as it's expanding. The browser kinda does this, but due to padding on the textarea the bottom is always cut off a little bit.
This could be fixed with something like textarea.addEventListener('grow', window.scroll({ top: 9999 }))
I don’t think that's safe. What if the textarea is 200vh
and the user is typing at the top? A resize would move the caret out of the viewport. Scrolling while typing is dangerous and it's not easy to find the position of the caret on scree if I remember correctly.
It'd be nice to make this part of fit-textarea
, but also even just moving the caret higher while the user is typing feels unnatural. Essentially, a line break would move the caret at the beginning of the same line on screen, like a type-writer. 🤔
Would be nice to be able to listen to
shrink
/expand
events on the textarea element.Use case: I have an auto-fit textarea at the bottom of a page, and I'd like to keep the vertical scroll all the way down as it's expanding. The browser kinda does this, but due to padding on the textarea the bottom is always cut off a little bit.