automatically focus the message input when the user selects another channel

This commit is contained in:
hippoz 2022-08-31 12:07:25 +03:00
parent 4080e69b11
commit e1490f1081
Signed by: hippoz
GPG key ID: 7C52899193467641

View file

@ -1,8 +1,9 @@
<script>
import { onDestroy, onMount } from "svelte";
import { ArrowUpIcon } from "svelte-feather-icons";
import request from "../request";
import { apiRoute, getItem } from "../storage";
import { messagesStoreProvider, overlayStore, smallViewport, typingStore, userInfoStore } from "../stores";
import { messagesStoreProvider, overlayStore, selectedChannel, smallViewport, typingStore, userInfoStore } from "../stores";
export let channel;
let messageInput = "";
@ -90,6 +91,11 @@
const onInput = () => {
typingStore.didInputKey();
};
// Focus the text area when the component first loads, or when the user selects another channel
const focusTextarea = () => messageTextarea && messageTextarea.focus();
onMount(focusTextarea);
onDestroy(selectedChannel.subscribe(focusTextarea));
</script>
<style>