web/sidebar: automatically scroll to active tab
This commit is contained in:
parent
65c14d41fa
commit
2ea3ca1a07
1 changed files with 14 additions and 0 deletions
|
@ -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}
|
||||||
|
|
Loading…
Reference in a new issue