Focus the chat whenever a button is pressed anywhere

main
Charlotte Som 2021-12-24 00:42:17 +00:00
parent d446869a28
commit 20fecd6891
1 changed files with 9 additions and 0 deletions

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();