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

145
Views
textarea does not auto focus even when set to auto focus
<textarea
  className="input"
  ref={textarea_ref}
  name="the-textarea"
  id="the-textarea"
  maxLength="150"
  placeholder="see guidelines for suggestions..."
  autoFocus
  onChange={(e) => input_text(e.target.value)}
  value={validated_text}
></textarea>

What might be some other factors that will cause the textarea to not auto focus when initialized?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

autofocus is defined to work reliably only on page load

So it might not work as you expected in Reactjs Component where you are changing/updating DOM or open a new Modal.


I would suggest using useRef instead:

import React, { useEffect, useRef } from "react";

export default function App() {
  const textarea_ref = useRef();
  useEffect(() => {
    textarea_ref.current.focus();
  });
  return (
    <textarea
      className="input"
      ref={textarea_ref}
      name="the-textarea"
      id="the-textarea"
      maxLength="150"
      placeholder="see guidelines for suggestions..."
    ></textarea>
  );
}

about 4 years ago · Juan Pablo Isaza 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!