mirror of
https://github.com/wukko/cobalt.git
synced 2025-05-09 10:14:26 +02:00
web/sidebar: automatically scroll to active tab
This commit is contained in:
parent
65c14d41fa
commit
2ea3ca1a07
@ -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…
x
Reference in New Issue
Block a user