From 8ea1750f1a22dd30a78cb46b04deb0847e20f05a Mon Sep 17 00:00:00 2001 From: bytedream Date: Sat, 28 Dec 2024 02:20:37 +0100 Subject: [PATCH] fix scroll position resetting on admin panel --- .../PaginationTableBody.svelte | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/lib/components/PaginationTable/PaginationTableBody.svelte b/src/lib/components/PaginationTable/PaginationTableBody.svelte index e6498d5..3422ea9 100644 --- a/src/lib/components/PaginationTable/PaginationTableBody.svelte +++ b/src/lib/components/PaginationTable/PaginationTableBody.svelte @@ -6,6 +6,21 @@ let bodyElem: HTMLTableSectionElement; let intersectionElem: HTMLElement; + async function onUpdateProxy() { + let scrollElem: HTMLElement | null = bodyElem; + while (scrollElem && scrollElem.scrollHeight <= scrollElem.clientHeight) { + scrollElem = scrollElem.parentElement; + } + + const scrollTop = scrollElem?.scrollTop ?? 0; + + await onUpdate(); + + if (scrollElem) scrollElem.scrollTop = scrollTop; + + await tick(); + } + async function getIntersectionElement(): Promise { if (!bodyElem.lastElementChild) { await new Promise((resolve) => { @@ -21,8 +36,7 @@ } onMount(async () => { - await onUpdate(); - await tick(); + await onUpdateProxy(); if (!bodyElem) return; @@ -33,8 +47,7 @@ const rows = bodyElem.rows.length; - await onUpdate(); - await tick(); + await onUpdateProxy(); if (rows === bodyElem.rows.length) return; observer.observe((intersectionElem = await getIntersectionElement()));