Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

147
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda