mirror of
https://github.com/youwen5/site.git
synced 2024-11-24 17:33:51 -08:00
feat: close mobile toc when link is clicked
This commit is contained in:
parent
f26ec6bd43
commit
f6b4dfa709
1 changed files with 10 additions and 2 deletions
|
@ -15,10 +15,16 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
$: currentDisplayed = $tocStore.activeItem ? $tocStore.activeItem.text : placeholder;
|
$: currentDisplayed = $tocStore.activeItem ? $tocStore.activeItem.text : placeholder;
|
||||||
|
|
||||||
|
let value: string;
|
||||||
|
|
||||||
|
const close = () => {
|
||||||
|
value = '';
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<nav class="fixed top-24 left-0 w-full bg-background bg-opacity-50 backdrop-blur-lg z-30 lg:hidden">
|
<nav class="fixed top-24 left-0 w-full bg-background bg-opacity-50 backdrop-blur-lg z-30 lg:hidden">
|
||||||
<Accordion.Root class="px-8">
|
<Accordion.Root class="px-8" bind:value>
|
||||||
<Accordion.Item value="toc">
|
<Accordion.Item value="toc">
|
||||||
<Accordion.Trigger
|
<Accordion.Trigger
|
||||||
class="text-xl flex w-full flex-1 items-center justify-between py-1 font-medium transition-all [&[data-state=open]>span>svg]:rotate-180"
|
class="text-xl flex w-full flex-1 items-center justify-between py-1 font-medium transition-all [&[data-state=open]>span>svg]:rotate-180"
|
||||||
|
@ -34,9 +40,11 @@
|
||||||
{#each $tocStore.items.values() as tocItem}
|
{#each $tocStore.items.values() as tocItem}
|
||||||
{@const selected = $tocStore.activeItem === tocItem}
|
{@const selected = $tocStore.activeItem === tocItem}
|
||||||
<li class="border-l-secondary border-l-4 py-1" class:highlighted={selected}>
|
<li class="border-l-secondary border-l-4 py-1" class:highlighted={selected}>
|
||||||
<!-- svelte-ignore a11y-missing-attribute a11y-missing-content -->
|
<!-- svelte-ignore a11y-missing-attribute a11y-missing-content a11y-click-events-have-key-events a11y-interactive-supports-focus a11y -->
|
||||||
<a
|
<a
|
||||||
use:toclink={{ store: tocStore, tocItem, observe: true }}
|
use:toclink={{ store: tocStore, tocItem, observe: true }}
|
||||||
|
on:click={close}
|
||||||
|
role="button"
|
||||||
class={`hover:bg-muted px-2 py-1 rounded-r-sm transition-all ${calcTextClasses(tocItem.element)}`}
|
class={`hover:bg-muted px-2 py-1 rounded-r-sm transition-all ${calcTextClasses(tocItem.element)}`}
|
||||||
/>
|
/>
|
||||||
</li>
|
</li>
|
||||||
|
|
Loading…
Reference in a new issue