Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

235
Views
How to scroll up and down line by line in a textarea using up and down buttons with React.js

I have a textarea and two buttons (up and down).

How can I scroll up and down line by line in the textarea using the up and down buttons with React.js.

Something like as if I'm writing a note and I move the text cursor up and down the paragraphs using the up and down keys on my keyboard.

Image: https://i.stack.imgur.com/9eEXU.png

Simplified code:

    import React from "react";
    
    export default function App() {
      return (
        <div>
          <button>Up</button>
          <br />
          <textarea placeholder="YOUR NOTES" />
          <br />
          <button>Down</button>
        </div>
      );
    }
about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

A friend helped me out. I thought I should come back here and share the solution with everyone else who might need it in the future.

import React from "react";

const goUp = (id) => {
  var maxScrollTop = id.scrollHeight - id.clientHeight;
  if (id.scrollTop !== 0) {
    id.scrollTo({
      top: id.scrollTop - 10,
      left: 0,
      behavior: "smooth"
    });
  }
};
const goDown = (id) => {
  var maxScrollDown = id.scrollHeight - id.clientHeight;
  id.scrollTo({
    top: id.scrollTop + 10,
    left: 0,
    behavior: "smooth"
  });
};

export default function App() {
  const okay = document.getElementById("text");
  return (
    <div>
      <button onClick={() => goUp(okay)}>Up</button>
      <br />
      <textarea id="text" placeholder="YOUR NOTES" />
      <br />
      <button onClick={() => goDown(okay)}>Down</button>
    </div>
  );
}
about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!