diff --git a/src/lib/components/PaginationTable/PaginationTableBody.svelte b/src/lib/components/PaginationTable/PaginationTableBody.svelte index e6498d5..c24e199 100644 --- a/src/lib/components/PaginationTable/PaginationTableBody.svelte +++ b/src/lib/components/PaginationTable/PaginationTableBody.svelte @@ -6,6 +6,20 @@ 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(); + await tick(); + + if (scrollElem) scrollElem.scrollTop = scrollTop; + } + async function getIntersectionElement(): Promise { if (!bodyElem.lastElementChild) { await new Promise((resolve) => { @@ -21,8 +35,7 @@ } onMount(async () => { - await onUpdate(); - await tick(); + await onUpdateProxy(); if (!bodyElem) return; @@ -33,8 +46,7 @@ const rows = bodyElem.rows.length; - await onUpdate(); - await tick(); + await onUpdateProxy(); if (rows === bodyElem.rows.length) return; observer.observe((intersectionElem = await getIntersectionElement()));