Merge pull request #1450 from thecodingmachine/fixScrollChat

Chat scroll to bottom when it open
This commit is contained in:
David Négrier 2021-09-14 14:39:42 +02:00 committed by GitHub
commit 6ed4857b1d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,7 +3,7 @@
import { chatMessagesStore, chatVisibilityStore } from "../../Stores/ChatStore";
import ChatMessageForm from './ChatMessageForm.svelte';
import ChatElement from './ChatElement.svelte';
import {afterUpdate, beforeUpdate} from "svelte";
import {afterUpdate, beforeUpdate, onMount} from "svelte";
import {HtmlUtils} from "../../WebRtc/HtmlUtils";
let listDom: HTMLElement;
@ -15,6 +15,10 @@
autoscroll = listDom && (listDom.offsetHeight + listDom.scrollTop) > (listDom.scrollHeight - 20);
});
onMount(() => {
listDom.scrollTo(0, listDom.scrollHeight);
})
afterUpdate(() => {
if (autoscroll) listDom.scrollTo(0, listDom.scrollHeight);
});