Commit 8adb654966

8adb654966ff994a8219354ea6c03ebeac6b46df

parent: 237e8c6212

Unsigned

Duck <57977673+woducku@users.noreply.github.com> · 2026-04-16 03:48 UTC

Revert "feat: auto-open Collapsible when navigating to hash inside"

This reverts commit ccfa8040b8749a9162eb5dd628bd4da113920b94.

Layout: unified · split

docs/.vitepress/theme/components/Collapsible.vue +5 −26
@@ -1,36 +1,15 @@
11<script setup lang="ts">
2import { useEventListener } from '@vueuse/core'
3import { nextTick, onMounted, ref } from 'vue'
2import { ref } from 'vue'
43
5defineProps<{ title?: string }>()
4const props = defineProps<{
5 title?: string
6}>()
67
78const open = ref(false)
8const detailsRef = ref<HTMLDetailsElement | null>(null)
9
10function openForHash(hash: string) {
11 if (!hash || !detailsRef.value) return
12 const id = decodeURIComponent(hash).slice(1)
13 const target = id && document.getElementById(id)
14 if (!target || !detailsRef.value.contains(target)) return
15 open.value = true
16 nextTick(() => target.scrollIntoView({ block: 'start' }))
17}
18
19onMounted(() => openForHash(location.hash))
20useEventListener(window, 'hashchange', () => openForHash(location.hash))
21useEventListener(document, 'click', (e) => {
22 const link = (e.target as HTMLElement)?.closest?.<HTMLAnchorElement>('a[href*="#"]')
23 if (link?.hash) nextTick(() => openForHash(link.hash))
24}, { capture: true })
259</script>
2610
2711<template>
28 <details
29 ref="detailsRef"
30 class="details custom-block"
31 :open="open || undefined"
32 @toggle="open = ($event.target as HTMLDetailsElement).open"
33 >
12 <details class="details custom-block" :open="open || undefined" @toggle="open = ($event.target as HTMLDetailsElement).open">
3413 <summary>{{ title || 'Details' }}</summary>
3514 <slot />
3615 </details>