Focus the chat whenever a button is pressed anywhere

This commit is contained in:
Charlotte Som 2021-12-24 00:42:17 +00:00
parent d446869a28
commit 20fecd6891

View file

@ -43,6 +43,15 @@ export const setupChat = async (socket) => {
document.querySelector("#chatbox-container").style["display"] = "block";
setupChatboxEvents(socket);
window.addEventListener("keydown", event => {
try {
const isSelectionEmpty = window.getSelection().toString().length === 0;
if (event.code.match(/Key\w/) && isSelectionEmpty)
document.querySelector("#chatbox-send > input").focus()
} catch (_err) {
}
});
fixChatSize();
window.addEventListener("resize", () => {
fixChatSize();