Reset the <main> scroll on forward navigation
This commit is contained in:
parent
2b1a6257de
commit
7cd9a68ae3
1 changed files with 11 additions and 0 deletions
|
|
@ -12,6 +12,7 @@
|
||||||
import DeleteModal from "$lib/components/DeleteModal.svelte";
|
import DeleteModal from "$lib/components/DeleteModal.svelte";
|
||||||
import Toast from "$lib/components/Toast.svelte";
|
import Toast from "$lib/components/Toast.svelte";
|
||||||
import { page } from "$app/state";
|
import { page } from "$app/state";
|
||||||
|
import { afterNavigate } from "$app/navigation";
|
||||||
import { onMount } from "svelte";
|
import { onMount } from "svelte";
|
||||||
import { auth, restoreSession } from "$lib/auth.svelte";
|
import { auth, restoreSession } from "$lib/auth.svelte";
|
||||||
import { loadGroup } from "$lib/group.svelte";
|
import { loadGroup } from "$lib/group.svelte";
|
||||||
|
|
@ -29,6 +30,15 @@
|
||||||
const mode = MODE;
|
const mode = MODE;
|
||||||
const chatEnabled = true;
|
const chatEnabled = true;
|
||||||
|
|
||||||
|
// The main column is its own scroll container (overflow-y-auto) and persists
|
||||||
|
// across navigations, so SvelteKit's window-only scroll restoration never
|
||||||
|
// resets it. Scroll it back to top on forward navigation; leave back/forward
|
||||||
|
// (popstate) alone so returning to a listing keeps its place.
|
||||||
|
let mainEl = $state<HTMLElement | null>(null);
|
||||||
|
afterNavigate((nav) => {
|
||||||
|
if (nav.type !== "popstate") mainEl?.scrollTo(0, 0);
|
||||||
|
});
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
loadResources();
|
loadResources();
|
||||||
loadPartials();
|
loadPartials();
|
||||||
|
|
@ -111,6 +121,7 @@
|
||||||
>
|
>
|
||||||
<LeftSidebar {mode} {activeRoom} {activeResource} {contactsActive} />
|
<LeftSidebar {mode} {activeRoom} {activeResource} {contactsActive} />
|
||||||
<main
|
<main
|
||||||
|
bind:this={mainEl}
|
||||||
class="no-scrollbar md:min-h-0 md:overflow-y-auto {showDiscussions
|
class="no-scrollbar md:min-h-0 md:overflow-y-auto {showDiscussions
|
||||||
? 'md:flex-[3]'
|
? 'md:flex-[3]'
|
||||||
: 'md:flex-1'}
|
: 'md:flex-1'}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue