From 15ffbae34dcbacaa686457d0a397054b5bed5104 Mon Sep 17 00:00:00 2001 From: Nulo Date: Thu, 31 Aug 2023 14:28:35 -0300 Subject: [PATCH] mejorar scroll breadcrumbs --- src/views/Page/Breadcrumbs.svelte | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/views/Page/Breadcrumbs.svelte b/src/views/Page/Breadcrumbs.svelte index 119a0ba..5dfadef 100644 --- a/src/views/Page/Breadcrumbs.svelte +++ b/src/views/Page/Breadcrumbs.svelte @@ -7,6 +7,7 @@ import { derived } from "svelte/store"; import { getTitle } from "../../lib/getTitle"; import { routes } from "../../lib/routes"; + import type { HTMLOlAttributes } from "svelte/elements"; export let worldId: string; export let pageId: string; @@ -27,22 +28,27 @@ ); let breadcrumbsEl: HTMLDivElement; - const crumbsScrollToEnd = async () => { + let breadcrumbsListEl: HTMLOListElement; + const crumbsScrollToEnd = async (behavior: ScrollBehavior = "auto") => { await tick(); - breadcrumbsEl?.scroll({ + breadcrumbsEl.scroll({ left: breadcrumbsEl.scrollWidth, - behavior: "smooth", + behavior, }); }; - onMount(() => { - crumbsScrollToEnd(); + crumbsScrollToEnd("smooth"); + const resizeObserver = new ResizeObserver(() => + crumbsScrollToEnd("smooth"), + ); + resizeObserver.observe(breadcrumbsListEl); + return () => resizeObserver.disconnect(); + }); + onMount(() => { + const resizeObserver = new ResizeObserver(() => crumbsScrollToEnd()); + resizeObserver.observe(breadcrumbsEl); + return () => resizeObserver.disconnect(); }); - $: { - $crumbsTitles; - $pageBreadcrumbs; - crumbsScrollToEnd(); - } @@ -52,6 +58,7 @@ >
    {#each $pageBreadcrumbs as crumb, index}