web/sidebar: automatically scroll to active tab

This commit is contained in:
wukko 2024-06-17 00:31:07 +06:00
parent 65c14d41fa
commit 2ea3ca1a07
No known key found for this signature in database
GPG key ID: 3E30B3F26C7B4AA2

View file

@ -4,7 +4,19 @@
export let tabName: string; export let tabName: string;
export let tabLink: string; export let tabLink: string;
let tab: HTMLElement;
$: isTabActive = $page.url.pathname === tabLink; $: isTabActive = $page.url.pathname === tabLink;
const showTab = (e: HTMLElement | undefined) => {
if (e) {
e.scrollIntoView({});
}
}
$: if (isTabActive) {
showTab(tab)
}
</script> </script>
<a <a
@ -12,6 +24,8 @@
class="sidebar-tab" class="sidebar-tab"
class:active={isTabActive} class:active={isTabActive}
href={tabLink} href={tabLink}
bind:this={tab}
on:focus={() => showTab(tab)}
> >
<slot></slot> <slot></slot>
{tabName} {tabName}