I've seen this question asked and answered, but the answers are never applicable to my issue, meaning they don't really solve the issue, and they're old so it's possible new solutions exist.
I have textareas that all start out with 1 row. User input causes the tetxareas to grow to fit content. I want the user to be able to move between textareas (they're stacked vertically) using the arrow keys. The issue is, I only want the UP ARROW to move to previous textarea if caret is in the first line. Same goes for DOWN ARROW/bottom line.
First thing to note: looking for \n doesn't help because it isn't a new line, just wrapped text to fit into the textarea.
Second: I don't know if it's relevant info, but the width of textareas would be fixed, so maybe it's possible to get caret position and do some math to calculate if it's in the first row, although I'm not sure if that works because of word rap (i.e., the first row could contain x characters, but is wrapped and now only has y).
You would think that it's built in. When you hit UP ARROW when you're in the first line it moves caret to start of content. Is there a way to utilize that logic? I'm assuming it's built in. Same goes for the DOWN ARROW.
Again, I have seen this question asked but couldn't use any of the answers for my specific case. The textareas I'm using are not styled and the only info that's helpful is that they start with 1 row and are resized dynamically using this function:
const resizeTextarea = (textarea) => {
textarea.style.boxSizing = "border-box";
textarea.style.height = "auto";
textarea.style.height = `${textarea.scrollHeight}px`;
};
The textareas are also saved as objects in an array using useState. Should I maybe add some sort of increment to the object when it dynamically grows to fit content (calls this function) so that when a user hits an arrow key, I could tell how many "lines" are in that textarea.
Potential issue is that I still don't know how to figure out if the caret is in that first row/last row even if I know the amount of rows. I mean, I already know the clientHeight and that couldn't lead me to the promise land...
You would think that it's built in. When you hit UP ARROW when you're in the first line it moves caret to start of content. Is there a way to utilize that logic? I'm assuming it's built in. Same goes for the DOWN ARROW.
This part really interests me, but I'm not sure what code (or whose) is even doing it.