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

241
Vistas
How to make cursor always stay on textarea even if user clicks anywhere else on the page?

I'm developing a Chat application using Angular & Electron.

I want user's cursor always on textarea where user types the message. When user clicks anywhere else in the page, the cursor should not go away from text area. This helps user to type anytime from anywhere, it will type in textarea only.

I tried the following:

    setTimeout(() => {
      this.messageTextAreaInput.nativeElement.focus();
    }, 20);

I'm calling it on the textarea blur event. But this solution does not let me copy text from other messages. When I select any text from message history, my selection is lost.

Any other way to achieve this?

My app for reference: enter image description here

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

window.addEventListener("keydown", () => {document.getElementById("textarea").focus()});
<textarea id="textarea" ></textarea>

about 4 years ago · Juan Pablo Isaza Denunciar

0

Try this way. You can change focus element to your own element which can be focusable.

const focusOnTextInput = () => document.getElementById('input').focus();

document.addEventListener('click', focusOnTextInput);
document.addEventListener('DOMContentLoaded', focusOnTextInput);
<input type="text" id="input"/>

about 4 years ago · Juan Pablo Isaza Denunciar

0

You could try using something like

window.onclick = function(event) {
    if (!event.target.matches('.messageTextAreaInputClassName')) {
        document.getElementById('messageTextAreaInput').focus();
    }
}

So that clicking anywhere other than the text area will call the text area to focus.

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