Skip to content

Commit

Permalink
fix: clicks and visibility across devices.
Browse files Browse the repository at this point in the history
  • Loading branch information
ItzNotABug committed Nov 27, 2024
1 parent c735369 commit a0f6351
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
23 changes: 22 additions & 1 deletion src/lib/components/TocNav.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import TocTree from './TocTree.svelte';
import { cubicOut } from 'svelte/easing';
import { getTocCtx } from './TocRoot.svelte';
import { onMount } from 'svelte';
export let showToc = true;
Expand Down Expand Up @@ -37,8 +38,17 @@
}
};
}
// show toc by default on desktop
function handleResizeForTocTree() {
showToc = window.innerWidth >= 1024;
}
onMount(handleResizeForTocTree);
</script>

<svelte:window on:resize={handleResizeForTocTree} />

<section class="web-mobile-header">
<div class="web-is-only-mobile">
<button
Expand Down Expand Up @@ -170,7 +180,7 @@
border-block-start: unset;
}
@media (max-width: 768px) {
@media (max-width: 1024px) {
.web-mobile-header {
top: 0;
margin: 1rem 0;
Expand Down Expand Up @@ -203,4 +213,15 @@
display: block;
}
}
@media (min-width: 1024px) {
.web-mobile-header {
border-block-end: unset;
border-block-start: unset;
}
.toc-tree-holder {
margin-top: unset;
}
}
</style>
8 changes: 7 additions & 1 deletion src/lib/components/TocTree.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script lang="ts">
import { type TableOfContentsItem, type TableOfContentsElements, melt } from '@melt-ui/svelte';
import { getTocCtx } from './TocRoot.svelte';
import { browser } from '$app/environment';
export let tree: TableOfContentsItem[] = [];
export let activeHeadingIdxs: number[];
Expand All @@ -14,6 +15,11 @@
helpers: { isActive }
}
} = getTocCtx();
function onItemClick() {
const isDesktop = browser ? window.innerWidth >= 1024 : false;
if (!isDesktop) showToc = !showToc;
}
</script>

<ul class="web-page-steps-list text-sub-body font-medium">
Expand All @@ -24,7 +30,7 @@
class:is-selected={$isActive(heading.id)}
href="#{heading.id}"
use:melt={$item(heading.id)}
on:click|preventDefault={() => showToc = !showToc}
on:click|preventDefault={onItemClick}
>
<!-- eslint-disable-next-line svelte/no-at-html-tags -->
{@html heading.node.innerHTML}
Expand Down

0 comments on commit a0f6351

Please sign in to comment.