@@ -10,13 +10,10 @@ const props = defineProps<{
10
10
}>()
11
11
12
12
const {
13
- collapsed,
14
- collapsible,
15
13
isLink,
16
14
isActiveLink,
17
15
hasActiveLink,
18
- hasChildren,
19
- toggle
16
+ hasChildren
20
17
} = useSidebarControl (computed (() => props .item ))
21
18
22
19
const sectionTag = computed (() => (hasChildren .value ? ' section' : ` div ` ))
@@ -31,44 +28,59 @@ const textTag = computed(() => {
31
28
: ` h${props .depth + 2 } `
32
29
})
33
30
34
- const itemRole = computed (() => (isLink .value ? undefined : ' button' ))
35
-
36
31
const classes = computed (() => [
37
32
[` level-${props .depth } ` ],
38
- { collapsible: collapsible .value },
39
- { collapsed: collapsed .value },
40
33
{ ' is-link' : isLink .value },
41
34
{ ' is-active' : isActiveLink .value },
42
35
{ ' has-active' : hasActiveLink .value }
43
36
])
44
-
45
- function onItemInteraction(e : MouseEvent | Event ) {
46
- if (' key' in e && e .key !== ' Enter' ) {
47
- return
48
- }
49
- ! props .item .link && toggle ()
50
- }
51
-
52
- function onCaretClick() {
53
- props .item .link && toggle ()
54
- }
55
37
</script >
56
38
57
39
<template >
58
40
<component :is =" sectionTag" class =" VPSidebarItem" :class =" classes" >
41
+ <details
42
+ v-if =" item.text && item.collapsed != null && hasChildren"
43
+ class =" item"
44
+ :open =" !item.collapsed"
45
+ >
46
+ <summary >
47
+ <div class =" indicator" />
48
+
49
+ <VPLink
50
+ v-if =" item.link"
51
+ :tag =" linkTag"
52
+ class =" link"
53
+ :href =" item.link"
54
+ :rel =" item.rel"
55
+ :target =" item.target"
56
+ >
57
+ <component :is =" textTag" class =" text" v-html =" item.text" />
58
+ </VPLink >
59
+ <component v-else :is =" textTag" class =" text" v-html =" item.text" />
60
+
61
+ <div class =" caret" >
62
+ <span class =" vpi-chevron-right caret-icon" />
63
+ </div >
64
+ </summary >
65
+
66
+ <div class =" items" >
67
+ <template v-if =" depth < 5 " >
68
+ <VPSidebarItem
69
+ v-for =" i in item.items"
70
+ :key =" i.text"
71
+ :item =" i"
72
+ :depth =" depth + 1"
73
+ />
74
+ </template >
75
+ </div >
76
+ </details >
59
77
<div
60
- v-if =" item.text"
78
+ v-else
79
+ :is =" item.text"
61
80
class =" item"
62
- :role =" itemRole"
63
- v-on ="
64
- hasChildren
65
- ? { click: onItemInteraction, keydown: onItemInteraction }
66
- : {}
67
- "
68
- :tabindex =" hasChildren ? 0 : undefined"
69
81
>
70
82
<div class =" indicator" />
71
-
83
+
72
84
<VPLink
73
85
v-if =" item.link"
74
86
:tag =" linkTag"
@@ -80,21 +92,9 @@ function onCaretClick() {
80
92
<component :is =" textTag" class =" text" v-html =" item.text" />
81
93
</VPLink >
82
94
<component v-else :is =" textTag" class =" text" v-html =" item.text" />
83
-
84
- <div
85
- v-if =" item.collapsed != null && hasChildren"
86
- class =" caret"
87
- role =" button"
88
- aria-label =" toggle section"
89
- @click =" onCaretClick"
90
- @keydown.enter =" onCaretClick"
91
- tabindex =" 0"
92
- >
93
- <span class =" vpi-chevron-right caret-icon" />
94
- </div >
95
95
</div >
96
96
97
- <div v-if =" hasChildren" class =" items" >
97
+ <div v-if =" (item.collapsed == null || !item.text) && hasChildren" class =" items" >
98
98
<template v-if =" depth < 5 " >
99
99
<VPSidebarItem
100
100
v-for =" i in item.items"
@@ -112,7 +112,7 @@ function onCaretClick() {
112
112
padding-bottom : 24px ;
113
113
}
114
114
115
- .VPSidebarItem.collapsed. level-0 {
115
+ .VPSidebarItem.level-0 :has ( > details :not ([ open ])) {
116
116
padding-bottom : 10px ;
117
117
}
118
118
@@ -122,8 +122,22 @@ function onCaretClick() {
122
122
width : 100% ;
123
123
}
124
124
125
- .VPSidebarItem.collapsible > .item {
125
+ .VPSidebarItem details summary {
126
126
cursor : pointer ;
127
+ display : flex ;
128
+ justify-content : space-between ;
129
+
130
+ .link {
131
+ flex-grow : 0 ;
132
+ }
133
+
134
+ &::-webkit-details-marker {
135
+ display : none ;
136
+ }
137
+
138
+ &::marker {
139
+ content : ' ' ;
140
+ }
127
141
}
128
142
129
143
.indicator {
@@ -171,36 +185,30 @@ function onCaretClick() {
171
185
color : var (--vp-c-text-2 );
172
186
}
173
187
174
- .VPSidebarItem.level-0.is-link > .item > .link :hover .text ,
175
- .VPSidebarItem.level-1.is-link > .item > .link :hover .text ,
176
- .VPSidebarItem.level-2.is-link > .item > .link :hover .text ,
177
- .VPSidebarItem.level-3.is-link > .item > .link :hover .text ,
178
- .VPSidebarItem.level-4.is-link > .item > .link :hover .text ,
179
- .VPSidebarItem.level-5.is-link > .item > .link :hover .text {
180
- color : var (--vp-c-brand-1 );
181
- }
182
-
183
- .VPSidebarItem.level-0.has-active > .item > .text ,
184
- .VPSidebarItem.level-1.has-active > .item > .text ,
185
- .VPSidebarItem.level-2.has-active > .item > .text ,
186
- .VPSidebarItem.level-3.has-active > .item > .text ,
187
- .VPSidebarItem.level-4.has-active > .item > .text ,
188
- .VPSidebarItem.level-5.has-active > .item > .text ,
189
- .VPSidebarItem.level-0.has-active > .item > .link > .text ,
190
- .VPSidebarItem.level-1.has-active > .item > .link > .text ,
191
- .VPSidebarItem.level-2.has-active > .item > .link > .text ,
192
- .VPSidebarItem.level-3.has-active > .item > .link > .text ,
193
- .VPSidebarItem.level-4.has-active > .item > .link > .text ,
194
- .VPSidebarItem.level-5.has-active > .item > .link > .text {
195
- color : var (--vp-c-text-1 );
196
- }
197
-
198
- .VPSidebarItem.level-0.is-active > .item .link > .text ,
199
- .VPSidebarItem.level-1.is-active > .item .link > .text ,
200
- .VPSidebarItem.level-2.is-active > .item .link > .text ,
201
- .VPSidebarItem.level-3.is-active > .item .link > .text ,
202
- .VPSidebarItem.level-4.is-active > .item .link > .text ,
203
- .VPSidebarItem.level-5.is-active > .item .link > .text {
188
+ .VPSidebarItem.level-0.is-active > .item > summary .text ,
189
+ .VPSidebarItem.level-1.is-active > .item > summary .text ,
190
+ .VPSidebarItem.level-2.is-active > .item > summary .text ,
191
+ .VPSidebarItem.level-3.is-active > .item > summary .text ,
192
+ .VPSidebarItem.level-4.is-active > .item > summary .text ,
193
+ .VPSidebarItem.level-5.is-active > .item > summary .text ,
194
+ .VPSidebarItem.level-0.is-active > .item > .link > .text ,
195
+ .VPSidebarItem.level-1.is-active > .item > .link > .text ,
196
+ .VPSidebarItem.level-2.is-active > .item > .link > .text ,
197
+ .VPSidebarItem.level-3.is-active > .item > .link > .text ,
198
+ .VPSidebarItem.level-4.is-active > .item > .link > .text ,
199
+ .VPSidebarItem.level-5.is-active > .item > .link > .text ,
200
+ .VPSidebarItem.level-0 .link :hover > .text ,
201
+ .VPSidebarItem.level-1 .link :hover > .text ,
202
+ .VPSidebarItem.level-2 .link :hover > .text ,
203
+ .VPSidebarItem.level-3 .link :hover > .text ,
204
+ .VPSidebarItem.level-4 .link :hover > .text ,
205
+ .VPSidebarItem.level-5 .link :hover > .text ,
206
+ .VPSidebarItem.level-0 .link :focus > .text ,
207
+ .VPSidebarItem.level-1 .link :focus > .text ,
208
+ .VPSidebarItem.level-2 .link :focus > .text ,
209
+ .VPSidebarItem.level-3 .link :focus > .text ,
210
+ .VPSidebarItem.level-4 .link :focus > .text ,
211
+ .VPSidebarItem.level-5 .link :focus > .text {
204
212
color : var (--vp-c-brand-1 );
205
213
}
206
214
@@ -231,7 +239,7 @@ function onCaretClick() {
231
239
transition : transform 0.25s ;
232
240
}
233
241
234
- .VPSidebarItem.collapsed .caret-icon {
242
+ .VPSidebarItem > details :not ([ open ]) > summary .caret-icon {
235
243
transform : rotate (0 );
236
244
}
237
245
@@ -243,8 +251,4 @@ function onCaretClick() {
243
251
border-left : 1px solid var (--vp-c-divider );
244
252
padding-left : 16px ;
245
253
}
246
-
247
- .VPSidebarItem.collapsed .items {
248
- display : none ;
249
- }
250
254
</style >
0 commit comments