Skip to content

Commit

Permalink
feat: scroll position after navigation (#107)
Browse files Browse the repository at this point in the history
fix: scroll position after navigation
  • Loading branch information
jrasm91 authored Feb 6, 2025
1 parent 0497aee commit 9cc409f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
12 changes: 5 additions & 7 deletions src/docs/components/ComponentPage.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import { Container, Heading, Scrollable, type ContainerSize } from '@immich/ui';
import { Container, Heading, type ContainerSize } from '@immich/ui';
import type { Snippet } from 'svelte';
type Props = {
Expand All @@ -23,10 +23,8 @@
</div>
</nav>

<Scrollable>
<Container {size} class="flex flex-col p-4">
<Heading size="large">{name}</Heading>
{@render children?.()}
</Container>
</Scrollable>
<Container {size} class="flex flex-col p-4">
<Heading size="large">{name}</Heading>
{@render children?.()}
</Container>
</div>
2 changes: 1 addition & 1 deletion src/lib/components/AppShell/AppShell.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
{#if sidebar}
{@render sidebar?.snippet()}
{/if}
<Scrollable class="grow">
<Scrollable class="grow" resetOnNavigate>
{@render children?.()}
</Scrollable>
</div>
Expand Down
13 changes: 11 additions & 2 deletions src/lib/components/Scrollable/Scrollable.svelte
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
<script lang="ts">
import { afterNavigate } from '$app/navigation';
import { cleanClass } from '$lib/utils.js';
import type { Snippet } from 'svelte';
type Props = {
class?: string;
children?: Snippet;
transition?: TransitionEvent;
ref?: HTMLDivElement;
resetOnNavigate?: boolean;
};
const { class: className, children }: Props = $props();
let { resetOnNavigate = false, class: className, children, ref = $bindable() }: Props = $props();
afterNavigate(() => {
if (resetOnNavigate) {
ref?.scrollTo(0, 0);
}
});
</script>

<div class={cleanClass('immich-scrollbar h-full w-full overflow-auto', className)}>
<div bind:this={ref} class={cleanClass('immich-scrollbar h-full w-full overflow-auto', className)}>
{@render children?.()}
</div>

Expand Down

0 comments on commit 9cc409f

Please sign in to comment.