Skip to content

best way to save what you love

web/sidebar: automatically scroll to active tab

wukko2ea3ca1a07cf
diff --git a/web/src/components/sidebar/SidebarTab.svelte b/web/src/components/sidebar/SidebarTab.svelte
index 36b50f6c..87bf8cd0 100644
--- a/web/src/components/sidebar/SidebarTab.svelte
+++ b/web/src/components/sidebar/SidebarTab.svelte
@@ -4,7 +4,19 @@
export let tabName: string;
export let tabLink: string;
+ let tab: HTMLElement;
+
$: isTabActive = $page.url.pathname === tabLink;
+
+ const showTab = (e: HTMLElement | undefined) => {
+ if (e) {
+ e.scrollIntoView({});
+ }
+ }
+
+ $: if (isTabActive) {
+ showTab(tab)
+ }
</script>
<a
@@ -12,6 +24,8 @@
class="sidebar-tab"
class:active={isTabActive}
href={tabLink}
+ bind:this={tab}
+ on:focus={() => showTab(tab)}
>
<slot></slot>
{tabName}