Issue
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?
Solution
window.addEventListener("keydown", () => {document.getElementById("textarea").focus()});
<textarea id="textarea" ></textarea>
Answered By – dangerousmanleesanghyeon
Answer Checked By – Timothy Miller (AngularFixing Admin)