@ui-sdk/vue 0.0.0-stage → 0.1.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (262) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +10 -2
  3. package/dist/accordion.d.ts +561 -0
  4. package/dist/accordion.js +24 -0
  5. package/dist/agent.d.ts +2 -0
  6. package/dist/agent.js +7 -0
  7. package/dist/alert-dialog.d.ts +231 -0
  8. package/dist/alert-dialog.js +33 -0
  9. package/dist/async-options.d.ts +18 -0
  10. package/dist/async-options.js +40 -0
  11. package/dist/autocomplete.d.ts +384 -0
  12. package/dist/autocomplete.js +344 -0
  13. package/dist/avatar.d.ts +40 -0
  14. package/dist/avatar.js +28 -0
  15. package/dist/button.d.ts +52 -0
  16. package/dist/button.js +43 -0
  17. package/dist/calendar-context.d.ts +10 -0
  18. package/dist/calendar-context.js +7 -0
  19. package/dist/calendar.d.ts +311 -0
  20. package/dist/calendar.js +349 -0
  21. package/dist/carousel.d.ts +236 -0
  22. package/dist/carousel.js +204 -0
  23. package/dist/checkbox.d.ts +211 -0
  24. package/dist/checkbox.js +151 -0
  25. package/dist/children.d.ts +41 -0
  26. package/dist/children.js +135 -0
  27. package/dist/collapsible.d.ts +54 -0
  28. package/dist/collapsible.js +18 -0
  29. package/dist/color-picker.d.ts +187 -0
  30. package/dist/color-picker.js +158 -0
  31. package/dist/color.d.ts +2 -0
  32. package/dist/color.js +21 -0
  33. package/dist/combobox.d.ts +517 -0
  34. package/dist/combobox.js +531 -0
  35. package/dist/command.d.ts +322 -0
  36. package/dist/command.js +345 -0
  37. package/dist/controller-target.d.ts +49 -0
  38. package/dist/controller-target.js +112 -0
  39. package/dist/create-parts.d.ts +126 -0
  40. package/dist/create-parts.js +206 -0
  41. package/dist/date-input.d.ts +133 -0
  42. package/dist/date-input.js +31 -0
  43. package/dist/date-picker.d.ts +328 -0
  44. package/dist/date-picker.js +354 -0
  45. package/dist/date.d.ts +2 -0
  46. package/dist/date.js +59 -0
  47. package/dist/dialog-parts.d.ts +259 -0
  48. package/dist/dialog-parts.js +300 -0
  49. package/dist/dialog.d.ts +251 -0
  50. package/dist/dialog.js +25 -0
  51. package/dist/drawer.d.ts +304 -0
  52. package/dist/drawer.js +373 -0
  53. package/dist/editor-context.d.ts +4 -0
  54. package/dist/editor-context.js +5 -0
  55. package/dist/field-context.d.ts +26 -0
  56. package/dist/field-context.js +44 -0
  57. package/dist/field.d.ts +154 -0
  58. package/dist/field.js +240 -0
  59. package/dist/file-input.d.ts +212 -0
  60. package/dist/file-input.js +255 -0
  61. package/dist/form-inputs.d.ts +16 -0
  62. package/dist/form-inputs.js +25 -0
  63. package/dist/gesture.d.ts +1 -0
  64. package/dist/gesture.js +15 -0
  65. package/dist/history.d.ts +2 -0
  66. package/dist/history.js +11 -0
  67. package/dist/hover-card.d.ts +137 -0
  68. package/dist/hover-card.js +153 -0
  69. package/dist/image-cropper.d.ts +74 -0
  70. package/dist/image-cropper.js +36 -0
  71. package/dist/image.d.ts +2 -0
  72. package/dist/image.js +5 -0
  73. package/dist/index.d.ts +59 -0
  74. package/dist/index.js +60 -0
  75. package/dist/input.d.ts +120 -0
  76. package/dist/input.js +73 -0
  77. package/dist/item-icon.d.ts +34 -0
  78. package/dist/item-icon.js +63 -0
  79. package/dist/label.d.ts +16 -0
  80. package/dist/label.js +8 -0
  81. package/dist/lifecycle.d.ts +11 -0
  82. package/dist/lifecycle.js +91 -0
  83. package/dist/list-items.d.ts +38 -0
  84. package/dist/list-items.js +59 -0
  85. package/dist/list-text.d.ts +7 -0
  86. package/dist/list-text.js +15 -0
  87. package/dist/listbox.d.ts +273 -0
  88. package/dist/listbox.js +126 -0
  89. package/dist/menu.d.ts +678 -0
  90. package/dist/menu.js +607 -0
  91. package/dist/menubar-context.d.ts +5 -0
  92. package/dist/menubar-context.js +5 -0
  93. package/dist/menubar.d.ts +61 -0
  94. package/dist/menubar.js +48 -0
  95. package/dist/meter.d.ts +41 -0
  96. package/dist/meter.js +37 -0
  97. package/dist/navigation-menu.d.ts +228 -0
  98. package/dist/navigation-menu.js +195 -0
  99. package/dist/number-input.d.ts +176 -0
  100. package/dist/number-input.js +231 -0
  101. package/dist/number.d.ts +2 -0
  102. package/dist/number.js +39 -0
  103. package/dist/nuxt/entries.json +977 -0
  104. package/dist/nuxt/module.d.ts +18 -0
  105. package/dist/nuxt/module.js +31 -0
  106. package/dist/nuxt/registrations.d.ts +22 -0
  107. package/dist/nuxt/registrations.js +22 -0
  108. package/dist/observe.d.ts +2 -0
  109. package/dist/observe.js +7 -0
  110. package/dist/otp-input.d.ts +142 -0
  111. package/dist/otp-input.js +130 -0
  112. package/dist/overlays.d.ts +40 -0
  113. package/dist/overlays.js +118 -0
  114. package/dist/pagination.d.ts +201 -0
  115. package/dist/pagination.js +146 -0
  116. package/dist/password-input.d.ts +144 -0
  117. package/dist/password-input.js +134 -0
  118. package/dist/popover.d.ts +211 -0
  119. package/dist/popover.js +258 -0
  120. package/dist/popup.d.ts +60 -0
  121. package/dist/popup.js +89 -0
  122. package/dist/preferences.d.ts +44 -0
  123. package/dist/preferences.js +102 -0
  124. package/dist/primitive.d.ts +2 -0
  125. package/dist/primitive.js +11 -0
  126. package/dist/progress.d.ts +41 -0
  127. package/dist/progress.js +37 -0
  128. package/dist/radio.d.ts +164 -0
  129. package/dist/radio.js +145 -0
  130. package/dist/rating.d.ts +149 -0
  131. package/dist/rating.js +146 -0
  132. package/dist/renderless.d.ts +4 -0
  133. package/dist/renderless.js +28 -0
  134. package/dist/resizable.d.ts +54 -0
  135. package/dist/resizable.js +22 -0
  136. package/dist/scroll-area.d.ts +72 -0
  137. package/dist/scroll-area.js +77 -0
  138. package/dist/segmented-control.d.ts +151 -0
  139. package/dist/segmented-control.js +110 -0
  140. package/dist/segmented-input.d.ts +76 -0
  141. package/dist/segmented-input.js +115 -0
  142. package/dist/select.d.ts +458 -0
  143. package/dist/select.js +468 -0
  144. package/dist/separator.d.ts +14 -0
  145. package/dist/separator.js +8 -0
  146. package/dist/shortcuts.d.ts +32 -0
  147. package/dist/shortcuts.js +56 -0
  148. package/dist/slider.d.ts +65 -0
  149. package/dist/slider.js +194 -0
  150. package/dist/switch.d.ts +103 -0
  151. package/dist/switch.js +71 -0
  152. package/dist/tabs.d.ts +338 -0
  153. package/dist/tabs.js +27 -0
  154. package/dist/text-control.d.ts +89 -0
  155. package/dist/text-control.js +51 -0
  156. package/dist/text-match.d.ts +2 -0
  157. package/dist/text-match.js +7 -0
  158. package/dist/textarea.d.ts +106 -0
  159. package/dist/textarea.js +68 -0
  160. package/dist/time-input.d.ts +131 -0
  161. package/dist/time-input.js +32 -0
  162. package/dist/timeline.d.ts +81 -0
  163. package/dist/timeline.js +30 -0
  164. package/dist/toast-parts.d.ts +203 -0
  165. package/dist/toast-parts.js +270 -0
  166. package/dist/toast.d.ts +2 -0
  167. package/dist/toast.js +21 -0
  168. package/dist/toggle-props.d.ts +22 -0
  169. package/dist/toggle-props.js +14 -0
  170. package/dist/toggle.d.ts +199 -0
  171. package/dist/toggle.js +129 -0
  172. package/dist/token-input.d.ts +136 -0
  173. package/dist/token-input.js +214 -0
  174. package/dist/toolbar-context.d.ts +7 -0
  175. package/dist/toolbar-context.js +20 -0
  176. package/dist/toolbar.d.ts +120 -0
  177. package/dist/toolbar.js +77 -0
  178. package/dist/tooltip.d.ts +160 -0
  179. package/dist/tooltip.js +224 -0
  180. package/dist/tree.d.ts +300 -0
  181. package/dist/tree.js +209 -0
  182. package/dist/trigger-menu.d.ts +452 -0
  183. package/dist/trigger-menu.js +254 -0
  184. package/dist/use-primitive.d.ts +132 -0
  185. package/dist/use-primitive.js +462 -0
  186. package/dist/waterfall.d.ts +201 -0
  187. package/dist/waterfall.js +171 -0
  188. package/docs/README.md +89 -0
  189. package/docs/agents.md +1523 -0
  190. package/docs/components/accordion.md +1369 -0
  191. package/docs/components/alert-dialog.md +799 -0
  192. package/docs/components/autocomplete.md +1857 -0
  193. package/docs/components/avatar.md +272 -0
  194. package/docs/components/button.md +435 -0
  195. package/docs/components/calendar.md +1589 -0
  196. package/docs/components/carousel.md +1171 -0
  197. package/docs/components/checkbox.md +1008 -0
  198. package/docs/components/collapsible.md +536 -0
  199. package/docs/components/color-picker.md +706 -0
  200. package/docs/components/combobox.md +3504 -0
  201. package/docs/components/command.md +1481 -0
  202. package/docs/components/date-input.md +536 -0
  203. package/docs/components/date-picker.md +1244 -0
  204. package/docs/components/dialog.md +1397 -0
  205. package/docs/components/drawer.md +1166 -0
  206. package/docs/components/field.md +538 -0
  207. package/docs/components/file-input.md +611 -0
  208. package/docs/components/hover-card.md +505 -0
  209. package/docs/components/image-cropper.md +556 -0
  210. package/docs/components/input.md +306 -0
  211. package/docs/components/label.md +203 -0
  212. package/docs/components/listbox.md +1004 -0
  213. package/docs/components/menu.md +1229 -0
  214. package/docs/components/menubar.md +443 -0
  215. package/docs/components/meter.md +315 -0
  216. package/docs/components/navigation-menu.md +1523 -0
  217. package/docs/components/number-input.md +1029 -0
  218. package/docs/components/otp-input.md +512 -0
  219. package/docs/components/pagination.md +613 -0
  220. package/docs/components/password-input.md +649 -0
  221. package/docs/components/popover.md +1448 -0
  222. package/docs/components/preferences.md +208 -0
  223. package/docs/components/progress.md +423 -0
  224. package/docs/components/radio.md +785 -0
  225. package/docs/components/rating.md +416 -0
  226. package/docs/components/resizable.md +910 -0
  227. package/docs/components/scroll-area.md +915 -0
  228. package/docs/components/segmented-control.md +435 -0
  229. package/docs/components/select.md +2015 -0
  230. package/docs/components/separator.md +229 -0
  231. package/docs/components/slider.md +1084 -0
  232. package/docs/components/switch.md +565 -0
  233. package/docs/components/tabs.md +944 -0
  234. package/docs/components/textarea.md +299 -0
  235. package/docs/components/time-input.md +224 -0
  236. package/docs/components/timeline.md +654 -0
  237. package/docs/components/toast.md +1224 -0
  238. package/docs/components/toggle.md +500 -0
  239. package/docs/components/token-input.md +953 -0
  240. package/docs/components/toolbar.md +739 -0
  241. package/docs/components/tooltip.md +818 -0
  242. package/docs/components/tree.md +1306 -0
  243. package/docs/components/trigger-menu.md +1223 -0
  244. package/docs/components/waterfall.md +717 -0
  245. package/docs/controllers.md +71 -0
  246. package/docs/core.md +8027 -0
  247. package/docs/custom-parts.md +89 -0
  248. package/docs/first-component.md +83 -0
  249. package/docs/forms.md +122 -0
  250. package/docs/installation.md +72 -0
  251. package/docs/introduction.md +32 -0
  252. package/docs/lists-and-menus.md +122 -0
  253. package/docs/llms.txt +1502 -0
  254. package/docs/parts-and-composition.md +85 -0
  255. package/docs/popups.md +108 -0
  256. package/docs/rendering.md +56 -0
  257. package/docs/server-rendering.md +180 -0
  258. package/docs/state-and-events.md +100 -0
  259. package/docs/styling-and-animation.md +148 -0
  260. package/docs/utilities/async-options.md +348 -0
  261. package/docs/utilities/shortcuts.md +159 -0
  262. package/package.json +352 -3
@@ -0,0 +1,1369 @@
1
+ # Accordion
2
+
3
+ Show and hide sections of content from their headings.
4
+
5
+ Use an Accordion for content people can explore one section at a time, such as answers, settings, or a course outline. Each heading is a button that opens its panel.
6
+
7
+ ```vue title="basic.vue"
8
+ <script setup lang="ts">
9
+ import { ChevronDownIcon } from "@lucide/vue"
10
+ import {
11
+ Accordion,
12
+ AccordionHeader,
13
+ AccordionItem,
14
+ AccordionPanel,
15
+ AccordionTrigger,
16
+ } from "@ui-sdk/vue/accordion"
17
+
18
+ const items = [
19
+ {
20
+ value: "shipping",
21
+ label: "What are your shipping options?",
22
+ content: [
23
+ "We offer standard (5 to 7 days), express (2 to 3 days) and overnight shipping.",
24
+ "Every order ships with tracking, and orders over $50 ship free.",
25
+ ],
26
+ },
27
+ {
28
+ value: "returns",
29
+ label: "What is your return policy?",
30
+ content: [
31
+ "Return any unused item in its original packaging within 30 days. Refunds arrive within 5 to 7 business days.",
32
+ ],
33
+ },
34
+ {
35
+ value: "support",
36
+ label: "How can I reach support?",
37
+ content: [
38
+ "Write to us by email or chat, or call us. We answer within 24 hours on business days.",
39
+ ],
40
+ },
41
+ ]
42
+ </script>
43
+
44
+ <template>
45
+ <Accordion :default-value="['shipping']">
46
+ <AccordionItem v-for="item in items" :key="item.value" :value="item.value">
47
+ <AccordionHeader>
48
+ <AccordionTrigger>
49
+ {{ item.label }}
50
+ <ChevronDownIcon aria-hidden="true" />
51
+ </AccordionTrigger>
52
+ </AccordionHeader>
53
+ <AccordionPanel>
54
+ <p v-for="paragraph in item.content" :key="paragraph">
55
+ {{ paragraph }}
56
+ </p>
57
+ </AccordionPanel>
58
+ </AccordionItem>
59
+ </Accordion>
60
+ </template>
61
+ ```
62
+
63
+ Press “What is your return policy?”. Its answer opens and the shipping answer closes. Press the same heading again to close it.
64
+
65
+ ## Installation
66
+
67
+ ```bash
68
+ npm install @ui-sdk/vue @ui-sdk/core
69
+ ```
70
+
71
+ ## Composition
72
+
73
+ Use the following composition to build an `Accordion`:
74
+
75
+ ```text
76
+ Accordion
77
+ ├── AccordionItem
78
+ │ ├── AccordionHeader
79
+ │ │ └── AccordionTrigger
80
+ │ └── AccordionPanel
81
+ └── AccordionItem
82
+ ├── AccordionHeader
83
+ │ └── AccordionTrigger
84
+ └── AccordionPanel
85
+ ```
86
+
87
+ Give every item a unique `value`. Put its trigger inside a heading, then add the panel it opens. The accordion's value is always an array of open item values, even when only one can be open.
88
+
89
+ `AccordionHeader` renders an `h3` by default. Use a heading level that fits the surrounding document. Tab moves between triggers; Enter or Space opens and closes their panels. Arrow keys, Home and End do nothing here: the APG removed them from the pattern, and a screen reader’s heading navigation already reaches each trigger.
90
+
91
+ ## Usage
92
+
93
+ Import the parts and put them together:
94
+
95
+ ```vue
96
+ <script setup lang="ts">
97
+ import {
98
+ Accordion,
99
+ AccordionHeader,
100
+ AccordionItem,
101
+ AccordionPanel,
102
+ AccordionTrigger,
103
+ } from "@ui-sdk/vue/accordion"
104
+ </script>
105
+
106
+ <template>
107
+ <Accordion>
108
+ <AccordionItem value="shipping">
109
+ <AccordionHeader>
110
+ <AccordionTrigger>Shipping</AccordionTrigger>
111
+ </AccordionHeader>
112
+ <AccordionPanel>Orders arrive in five to seven days.</AccordionPanel>
113
+ </AccordionItem>
114
+ </Accordion>
115
+ </template>
116
+ ```
117
+
118
+ ## Build Your Own
119
+
120
+ `@ui-sdk/vue/accordion` comes with a ready-made Accordion. If you'd like to build your own, with your own names, start from the `accordion` primitive in `@ui-sdk/core`:
121
+
122
+ ```ts title="faq.ts"
123
+ import { accordion } from "@ui-sdk/core/accordion"
124
+ import { createParts } from "@ui-sdk/vue/primitive"
125
+
126
+ const {
127
+ Root: FaqList,
128
+ Item: FaqItem,
129
+ Header: FaqHeading,
130
+ Trigger: FaqQuestion,
131
+ Panel: FaqAnswer,
132
+ } = createParts(accordion, {
133
+ root: "div",
134
+ item: "div",
135
+ header: "h3",
136
+ trigger: "button",
137
+ panel: "div",
138
+ })
139
+
140
+ export { FaqAnswer, FaqHeading, FaqItem, FaqList, FaqQuestion }
141
+ ```
142
+
143
+ ```vue
144
+ <template>
145
+ <FaqList>
146
+ <FaqItem value="shipping">
147
+ <FaqHeading>
148
+ <FaqQuestion>What are your shipping options?</FaqQuestion>
149
+ </FaqHeading>
150
+ <FaqAnswer>Standard, express and overnight.</FaqAnswer>
151
+ </FaqItem>
152
+ </FaqList>
153
+ </template>
154
+ ```
155
+
156
+ Each part keeps the behavior, state and data attributes of its ready-made counterpart. See [Rendering](../rendering.md) and [Custom Parts](../custom-parts.md) for more.
157
+
158
+ ## Multiple
159
+
160
+ Add `multiple` to let several items stay open. Opening one then leaves the others as they are.
161
+
162
+ ```vue title="multiple.vue"
163
+ <script setup lang="ts">
164
+ import { ChevronDownIcon } from "@lucide/vue"
165
+ import {
166
+ Accordion,
167
+ AccordionHeader,
168
+ AccordionItem,
169
+ AccordionPanel,
170
+ AccordionTrigger,
171
+ } from "@ui-sdk/vue/accordion"
172
+
173
+ const items = [
174
+ {
175
+ value: "notifications",
176
+ label: "Notification settings",
177
+ content: "Choose what we email you about, and how often.",
178
+ },
179
+ {
180
+ value: "privacy",
181
+ label: "Privacy and security",
182
+ content: "Turn on two-factor authentication and review signed-in devices.",
183
+ },
184
+ {
185
+ value: "billing",
186
+ label: "Billing and subscription",
187
+ content: "Update your payment method and download past invoices.",
188
+ },
189
+ ]
190
+ </script>
191
+
192
+ <template>
193
+ <Accordion multiple :default-value="['notifications']">
194
+ <AccordionItem v-for="item in items" :key="item.value" :value="item.value">
195
+ <AccordionHeader>
196
+ <AccordionTrigger>
197
+ {{ item.label }}
198
+ <ChevronDownIcon aria-hidden="true" />
199
+ </AccordionTrigger>
200
+ </AccordionHeader>
201
+ <AccordionPanel>
202
+ {{ item.content }}
203
+ </AccordionPanel>
204
+ </AccordionItem>
205
+ </Accordion>
206
+ </template>
207
+ ```
208
+
209
+ Open Privacy and security. Notification settings stays open; close either section independently.
210
+
211
+ ## Disabled
212
+
213
+ Set `disabled` on an item or on a single trigger to prevent changes, or on the accordion to disable every item. Disabled triggers stay in the tab order so people can still discover them. A disabled `<fieldset>` around the accordion disables it too.
214
+
215
+ ```vue title="disabled.vue"
216
+ <script setup lang="ts">
217
+ import { ChevronDownIcon } from "@lucide/vue"
218
+ import {
219
+ Accordion,
220
+ AccordionHeader,
221
+ AccordionItem,
222
+ AccordionPanel,
223
+ AccordionTrigger,
224
+ } from "@ui-sdk/vue/accordion"
225
+
226
+ const items = [
227
+ {
228
+ value: "access",
229
+ label: "Can I access my account history?",
230
+ content:
231
+ "Yes. Every order and payment from the last five years is in your account.",
232
+ },
233
+ {
234
+ value: "premium",
235
+ label: "Premium feature information",
236
+ content:
237
+ "Premium includes priority support and early access to new features.",
238
+ disabled: true,
239
+ },
240
+ {
241
+ value: "email",
242
+ label: "How do I update my email address?",
243
+ content:
244
+ "Open Settings, then Account, and change it there. We'll send a confirmation link.",
245
+ },
246
+ ]
247
+ </script>
248
+
249
+ <template>
250
+ <Accordion>
251
+ <AccordionItem v-for="item in items" :key="item.value" :value="item.value" :disabled="item.disabled">
252
+ <AccordionHeader>
253
+ <AccordionTrigger>
254
+ {{ item.label }}
255
+ <ChevronDownIcon aria-hidden="true" />
256
+ </AccordionTrigger>
257
+ </AccordionHeader>
258
+ <AccordionPanel>
259
+ {{ item.content }}
260
+ </AccordionPanel>
261
+ </AccordionItem>
262
+ </Accordion>
263
+ </template>
264
+ ```
265
+
266
+ Tab to Premium feature information. It stays focusable, and pressing it leaves its panel closed. Try “How do I update my email address?” instead.
267
+
268
+ <span id="behavior-and-options" />
269
+
270
+ ## Collapsible
271
+
272
+ Set `:collapsible="false"` when the open item should stay open until another item replaces it. Pair it with `:default-value="['overview']"` so a panel starts open.
273
+
274
+ The open trigger reports `aria-disabled="true"` because pressing it leaves its panel open.
275
+
276
+ ```vue
277
+ <Accordion :collapsible="false" :default-value="['overview']" />
278
+ ```
279
+
280
+ ```vue title="collapsible.vue"
281
+ <script setup lang="ts">
282
+ import { ChevronDownIcon } from "@lucide/vue"
283
+ import {
284
+ Accordion,
285
+ AccordionHeader,
286
+ AccordionItem,
287
+ AccordionPanel,
288
+ AccordionTrigger,
289
+ } from "@ui-sdk/vue/accordion"
290
+
291
+ const items = [
292
+ {
293
+ value: "overview",
294
+ label: "Overview",
295
+ content: "A summary of the project, its goals and its owners.",
296
+ },
297
+ {
298
+ value: "timeline",
299
+ label: "Timeline",
300
+ content: "Kickoff in March, beta in June and launch in September.",
301
+ },
302
+ {
303
+ value: "budget",
304
+ label: "Budget",
305
+ content: "Approved for two engineers and one designer for six months.",
306
+ },
307
+ ]
308
+ </script>
309
+
310
+ <template>
311
+ <Accordion :collapsible="false" :default-value="['overview']">
312
+ <AccordionItem v-for="item in items" :key="item.value" :value="item.value">
313
+ <AccordionHeader>
314
+ <AccordionTrigger>
315
+ {{ item.label }}
316
+ <ChevronDownIcon aria-hidden="true" />
317
+ </AccordionTrigger>
318
+ </AccordionHeader>
319
+ <AccordionPanel>
320
+ {{ item.content }}
321
+ </AccordionPanel>
322
+ </AccordionItem>
323
+ </Accordion>
324
+ </template>
325
+ ```
326
+
327
+ Open Timeline, then press it again. It stays open until you choose another heading.
328
+
329
+ ## Controlled
330
+
331
+ Use `v-model:value` to own the open items. [State and Events](../state-and-events.md) covers the shared pattern.
332
+
333
+ An item can refuse a change: call `details.cancel()` in its `@open-change` callback. Item callbacks run before the accordion's `@value-change`, including the item that would close when another opens. Canceling any one of them cancels the whole change. `@value-change` also gets the [reason](#reasons) for the change.
334
+
335
+ ```vue title="controlled.vue"
336
+ <script setup lang="ts">
337
+ import { ChevronDownIcon } from "@lucide/vue"
338
+ import type { ChangeDetails } from "@ui-sdk/core"
339
+ import { createAccordionController } from "@ui-sdk/core/accordion"
340
+ import {
341
+ Accordion,
342
+ AccordionHeader,
343
+ AccordionItem,
344
+ AccordionPanel,
345
+ AccordionTrigger,
346
+ } from "@ui-sdk/vue/accordion"
347
+ import { ref } from "vue"
348
+
349
+ const items = [
350
+ {
351
+ value: "account",
352
+ label: "Account",
353
+ content: "Your name, email address and profile photo.",
354
+ },
355
+ {
356
+ value: "security",
357
+ label: "Security",
358
+ content: "Your password, passkeys and two-factor authentication.",
359
+ },
360
+ {
361
+ value: "sessions",
362
+ label: "Sessions",
363
+ content: "Devices signed in to your account in the last 30 days.",
364
+ },
365
+ ]
366
+
367
+ const accordion = createAccordionController()
368
+
369
+ const value = ref(["account"])
370
+
371
+ function confirmClose(item: string, open: boolean, details: ChangeDetails) {
372
+ if (
373
+ !open &&
374
+ item === "security" &&
375
+ !window.confirm("Close the security settings?")
376
+ ) {
377
+ details.cancel()
378
+ }
379
+ }
380
+ </script>
381
+
382
+ <template>
383
+ <div>
384
+ <div data-slot="controls">
385
+ <button type="button" @click="accordion.open('security')">
386
+ Review security
387
+ </button>
388
+ </div>
389
+ <Accordion v-model:value="value" multiple :controller="accordion">
390
+ <AccordionItem
391
+ v-for="item in items"
392
+ :key="item.value"
393
+ :value="item.value"
394
+ @open-change="
395
+ (open: boolean, details: ChangeDetails) =>
396
+ confirmClose(item.value, open, details)
397
+ "
398
+ >
399
+ <AccordionHeader>
400
+ <AccordionTrigger>
401
+ {{ item.label }}
402
+ <ChevronDownIcon aria-hidden="true" />
403
+ </AccordionTrigger>
404
+ </AccordionHeader>
405
+ <AccordionPanel>
406
+ {{ item.content }}
407
+ </AccordionPanel>
408
+ </AccordionItem>
409
+ </Accordion>
410
+ </div>
411
+ </template>
412
+ ```
413
+
414
+ Press Security to open it, then press it again. Cancel the confirmation and Security stays open; accept it and the section closes.
415
+
416
+ ## Keep Mounted
417
+
418
+ A closed panel normally unmounts. Add `keep-mounted` to one panel or the whole accordion to keep its content hidden in the page. This preserves local state, such as a draft in a field.
419
+
420
+ ```vue title="keep-mounted.vue"
421
+ <script setup lang="ts">
422
+ import { ChevronDownIcon } from "@lucide/vue"
423
+ import {
424
+ Accordion,
425
+ AccordionHeader,
426
+ AccordionItem,
427
+ AccordionPanel,
428
+ AccordionTrigger,
429
+ } from "@ui-sdk/vue/accordion"
430
+ import { Field, FieldLabel } from "@ui-sdk/vue/field"
431
+ import { Textarea } from "@ui-sdk/vue/textarea"
432
+ </script>
433
+
434
+ <template>
435
+ <Accordion :default-value="['reply']">
436
+ <AccordionItem value="reply">
437
+ <AccordionHeader>
438
+ <AccordionTrigger>
439
+ Reply to this thread
440
+ <ChevronDownIcon aria-hidden="true" />
441
+ </AccordionTrigger>
442
+ </AccordionHeader>
443
+ <AccordionPanel keep-mounted>
444
+ <Field>
445
+ <FieldLabel>Message</FieldLabel>
446
+ <Textarea rows="3" placeholder="Write a reply…" />
447
+ </Field>
448
+ </AccordionPanel>
449
+ </AccordionItem>
450
+ <AccordionItem value="formatting">
451
+ <AccordionHeader>
452
+ <AccordionTrigger>
453
+ Formatting
454
+ <ChevronDownIcon aria-hidden="true" />
455
+ </AccordionTrigger>
456
+ </AccordionHeader>
457
+ <AccordionPanel>
458
+ <p>Use **bold**, _italics_ and `code`. Links paste as previews.</p>
459
+ </AccordionPanel>
460
+ </AccordionItem>
461
+ </Accordion>
462
+ </template>
463
+ ```
464
+
465
+ Write a message, switch to Formatting, then return to Reply to this thread. Your draft is still there.
466
+
467
+ ## Find in Page
468
+
469
+ Add `hidden-until-found` to keep closed panels available to the browser's Find command. A match opens the item immediately, without an animation, with the [reason](#reasons) `find-in-page`.
470
+
471
+ ```vue title="find-in-page.vue"
472
+ <script setup lang="ts">
473
+ import { ChevronDownIcon } from "@lucide/vue"
474
+ import {
475
+ Accordion,
476
+ AccordionHeader,
477
+ AccordionItem,
478
+ AccordionPanel,
479
+ AccordionTrigger,
480
+ } from "@ui-sdk/vue/accordion"
481
+
482
+ const items = [
483
+ {
484
+ value: "fruit",
485
+ label: "Which fruit do you stock?",
486
+ content: "Apples, pears, mangoes and, in summer, pineapple.",
487
+ },
488
+ {
489
+ value: "organic",
490
+ label: "Is it organic?",
491
+ content: "Everything we stock is certified organic.",
492
+ },
493
+ {
494
+ value: "delivery",
495
+ label: "When do you deliver?",
496
+ content: "Every weekday morning before 10.",
497
+ },
498
+ ]
499
+ </script>
500
+
501
+ <template>
502
+ <Accordion hidden-until-found>
503
+ <AccordionItem v-for="item in items" :key="item.value" :value="item.value">
504
+ <AccordionHeader>
505
+ <AccordionTrigger>
506
+ {{ item.label }}
507
+ <ChevronDownIcon aria-hidden="true" />
508
+ </AccordionTrigger>
509
+ </AccordionHeader>
510
+ <AccordionPanel>
511
+ {{ item.content }}
512
+ </AccordionPanel>
513
+ </AccordionItem>
514
+ </Accordion>
515
+ </template>
516
+ ```
517
+
518
+ Use your browser’s Find command to search for “pineapple”. The closed “Which fruit do you stock?” panel opens to reveal the match.
519
+
520
+ <span id="deep-links" />
521
+
522
+ A link to an element inside a closed panel can reveal it too. Give the target an `id` and link to it with a hash, such as `href="#refund-timeline"`.
523
+
524
+ ```vue title="deep-link.vue"
525
+ <script setup lang="ts">
526
+ import { ChevronDownIcon } from "@lucide/vue"
527
+ import {
528
+ Accordion,
529
+ AccordionHeader,
530
+ AccordionItem,
531
+ AccordionPanel,
532
+ AccordionTrigger,
533
+ } from "@ui-sdk/vue/accordion"
534
+ </script>
535
+
536
+ <template>
537
+ <div>
538
+ <nav data-slot="controls" aria-label="Jump to">
539
+ <a href="#refund-timeline">Jump to the refund timeline</a>
540
+ <a href="#return-label">Print a return label</a>
541
+ </nav>
542
+ <Accordion hidden-until-found>
543
+ <AccordionItem value="returns">
544
+ <AccordionHeader>
545
+ <AccordionTrigger>
546
+ Returns
547
+ <ChevronDownIcon aria-hidden="true" />
548
+ </AccordionTrigger>
549
+ </AccordionHeader>
550
+ <AccordionPanel>
551
+ <div data-slot="stack">
552
+ <p>
553
+ Return any unused item in its original packaging within 30 days.
554
+ </p>
555
+ <p id="return-label">
556
+ To print a return label, open the order and choose Return. The
557
+ label is free.
558
+ </p>
559
+ </div>
560
+ </AccordionPanel>
561
+ </AccordionItem>
562
+ <AccordionItem value="refunds">
563
+ <AccordionHeader>
564
+ <AccordionTrigger>
565
+ Refunds
566
+ <ChevronDownIcon aria-hidden="true" />
567
+ </AccordionTrigger>
568
+ </AccordionHeader>
569
+ <AccordionPanel>
570
+ <div data-slot="stack">
571
+ <p>Refunds go back to the card you paid with.</p>
572
+ <p id="refund-timeline">
573
+ Timeline: we inspect the item within 2 days of receiving it, and
574
+ your bank shows the refund 5 to 7 business days later.
575
+ </p>
576
+ </div>
577
+ </AccordionPanel>
578
+ </AccordionItem>
579
+ <AccordionItem value="exchanges">
580
+ <AccordionHeader>
581
+ <AccordionTrigger>
582
+ Exchanges
583
+ <ChevronDownIcon aria-hidden="true" />
584
+ </AccordionTrigger>
585
+ </AccordionHeader>
586
+ <AccordionPanel>
587
+ <div data-slot="stack">
588
+ <p>
589
+ Start a return, choose Exchange and pick the new size. Shipping
590
+ both ways is free.
591
+ </p>
592
+ </div>
593
+ </AccordionPanel>
594
+ </AccordionItem>
595
+ </Accordion>
596
+ </div>
597
+ </template>
598
+ ```
599
+
600
+ Press Jump to the refund timeline. The closed Refunds panel opens and the browser moves to the linked paragraph.
601
+
602
+ With `hidden-until-found`, Vue's server render writes `hidden="until-found"`, so closed panels are findable from the start. For an initial URL hash, [open the item explicitly](#url-hash).
603
+
604
+ ## Animation
605
+
606
+ Each part has a `data-slot`, such as `accordion-panel`. The panel exposes its measured height as `--accordion-panel-height`. Animate that height to or from zero with `data-starting-style` and `data-ending-style`:
607
+
608
+ ```css
609
+ [data-slot="accordion-panel"] {
610
+ height: var(--accordion-panel-height);
611
+ overflow: hidden;
612
+ transition: height 0.15s;
613
+
614
+ &:is([data-starting-style], [data-ending-style]) {
615
+ height: 0;
616
+ }
617
+ }
618
+ ```
619
+
620
+ The panel stays mounted until its exit animation finishes. An item's `@open-change-complete` runs afterward with the open state. A panel that starts open appears right away, with no animation and no completion callback.
621
+
622
+ ```vue title="animation.vue"
623
+ <script setup lang="ts">
624
+ import { ChevronDownIcon } from "@lucide/vue"
625
+ import {
626
+ Accordion,
627
+ AccordionHeader,
628
+ AccordionItem,
629
+ AccordionPanel,
630
+ AccordionTrigger,
631
+ } from "@ui-sdk/vue/accordion"
632
+
633
+ const items = [
634
+ {
635
+ value: "one",
636
+ label: "Why animate the height?",
637
+ content: "So the content below slides instead of jumping.",
638
+ },
639
+ {
640
+ value: "two",
641
+ label: "Where does the height come from?",
642
+ content:
643
+ "The panel measures itself and writes the result to a CSS variable while it animates.",
644
+ },
645
+ {
646
+ value: "three",
647
+ label: "Does it animate on first paint?",
648
+ content: "No. Panels open on the server or on mount show at once.",
649
+ },
650
+ ]
651
+ </script>
652
+
653
+ <template>
654
+ <Accordion :default-value="['one']">
655
+ <AccordionItem v-for="item in items" :key="item.value" :value="item.value">
656
+ <AccordionHeader>
657
+ <AccordionTrigger>
658
+ {{ item.label }}
659
+ <ChevronDownIcon aria-hidden="true" />
660
+ </AccordionTrigger>
661
+ </AccordionHeader>
662
+ <AccordionPanel>
663
+ {{ item.content }}
664
+ </AccordionPanel>
665
+ </AccordionItem>
666
+ </Accordion>
667
+ </template>
668
+ ```
669
+
670
+ Open or close an item. Its panel animates its height.
671
+
672
+ ## Expand All
673
+
674
+ With `multiple`, a controller's `openAll()` opens every enabled item. `closeAll()` closes every item that may close. [Controllers](../controllers.md) explains how to connect one.
675
+
676
+ ```vue title="expand-all.vue"
677
+ <script setup lang="ts">
678
+ import { ChevronDownIcon } from "@lucide/vue"
679
+ import type { ChangeDetails } from "@ui-sdk/core"
680
+ import { createAccordionController } from "@ui-sdk/core/accordion"
681
+ import {
682
+ Accordion,
683
+ AccordionHeader,
684
+ AccordionItem,
685
+ AccordionPanel,
686
+ AccordionTrigger,
687
+ } from "@ui-sdk/vue/accordion"
688
+ import type { ComponentPublicInstance } from "vue"
689
+
690
+ const weeks = [
691
+ {
692
+ value: "week-1",
693
+ label: "Week 1: Foundations",
694
+ content:
695
+ "Set up your editor, meet the command line and write your first script.",
696
+ },
697
+ {
698
+ value: "week-2",
699
+ label: "Week 2: Data and types",
700
+ content:
701
+ "Strings, numbers, lists and objects, and how to tell them apart when a program runs.",
702
+ },
703
+ {
704
+ value: "week-3",
705
+ label: "Week 3: Control flow",
706
+ content:
707
+ "Conditions, loops and functions. The project this week is a small text adventure.",
708
+ },
709
+ {
710
+ value: "week-4",
711
+ label: "Week 4: Working with files",
712
+ content:
713
+ "Read and write files, parse CSV and JSON, and handle the errors that come with them.",
714
+ },
715
+ {
716
+ value: "week-5",
717
+ label: "Week 5: Final project",
718
+ content:
719
+ "Build a tool you'll use yourself, then present it to the group in a five-minute demo.",
720
+ },
721
+ ]
722
+
723
+ const syllabus = createAccordionController()
724
+
725
+ const elements = new Map<string, HTMLElement>()
726
+ function setElement(
727
+ value: string,
728
+ instance: Element | ComponentPublicInstance | null
729
+ ) {
730
+ if (instance && "$el" in instance) {
731
+ elements.set(value, instance.$el as HTMLElement)
732
+ } else {
733
+ elements.delete(value)
734
+ }
735
+ }
736
+
737
+ let pressed: string | null = null
738
+ function openChange(value: string, open: boolean, details: ChangeDetails) {
739
+ if (open && details.reason === "trigger-press") {
740
+ pressed = value
741
+ } else if (pressed === value) {
742
+ pressed = null
743
+ }
744
+ }
745
+
746
+ function openChangeComplete(value: string, open: boolean) {
747
+ if (!open || pressed !== value) {
748
+ return
749
+ }
750
+ pressed = null
751
+ elements.get(value)?.scrollIntoView({ block: "nearest", behavior: "smooth" })
752
+ }
753
+ </script>
754
+
755
+ <template>
756
+ <div>
757
+ <div data-slot="controls">
758
+ <button type="button" @click="syllabus.openAll()">Expand all</button>
759
+ <button type="button" @click="syllabus.closeAll()">Collapse all</button>
760
+ </div>
761
+ <div data-slot="scroll">
762
+ <Accordion multiple :controller="syllabus">
763
+ <AccordionItem
764
+ v-for="week in weeks"
765
+ :key="week.value"
766
+ :ref="(instance) => setElement(week.value, instance)"
767
+ :value="week.value"
768
+ @open-change="
769
+ (open: boolean, details: ChangeDetails) =>
770
+ openChange(week.value, open, details)
771
+ "
772
+ @open-change-complete="
773
+ (open: boolean) => openChangeComplete(week.value, open)
774
+ "
775
+ >
776
+ <AccordionHeader>
777
+ <AccordionTrigger>
778
+ {{ week.label }}
779
+ <ChevronDownIcon aria-hidden="true" />
780
+ </AccordionTrigger>
781
+ </AccordionHeader>
782
+ <AccordionPanel>
783
+ {{ week.content }}
784
+ </AccordionPanel>
785
+ </AccordionItem>
786
+ </Accordion>
787
+ </div>
788
+ </div>
789
+ </template>
790
+ ```
791
+
792
+ Press Expand all or Collapse all. Open an individual week near the bottom to scroll it into view after its panel opens.
793
+
794
+ ## Nested
795
+
796
+ Put another accordion inside a panel when a section has its own expandable sections. Each accordion tracks its own items. Give the inner headings a lower level than the outer headings.
797
+
798
+ ```vue title="nested.vue"
799
+ <script setup lang="ts">
800
+ import { ChevronDownIcon } from "@lucide/vue"
801
+ import {
802
+ Accordion,
803
+ AccordionHeader,
804
+ AccordionItem,
805
+ AccordionPanel,
806
+ AccordionTrigger,
807
+ } from "@ui-sdk/vue/accordion"
808
+
809
+ const sections: {
810
+ value: string
811
+ label: string
812
+ content?: string
813
+ topics?: { value: string; label: string; content: string }[]
814
+ }[] = [
815
+ {
816
+ value: "profile",
817
+ label: "Profile",
818
+ content: "Your name, photo and the email address people see.",
819
+ },
820
+ {
821
+ value: "notifications",
822
+ label: "Notifications",
823
+ topics: [
824
+ {
825
+ value: "email",
826
+ label: "Email",
827
+ content: "A weekly digest, and mentions as they happen.",
828
+ },
829
+ {
830
+ value: "push",
831
+ label: "Push",
832
+ content: "Direct messages and replies to your comments.",
833
+ },
834
+ ],
835
+ },
836
+ {
837
+ value: "billing",
838
+ label: "Billing",
839
+ topics: [
840
+ {
841
+ value: "payment",
842
+ label: "Payment methods",
843
+ content: "A Visa card ending in 4242, used for every renewal.",
844
+ },
845
+ {
846
+ value: "invoices",
847
+ label: "Invoices",
848
+ content: "Download a PDF of any invoice from the last two years.",
849
+ },
850
+ ],
851
+ },
852
+ ]
853
+ </script>
854
+
855
+ <template>
856
+ <Accordion :default-value="['notifications']">
857
+ <AccordionItem v-for="section in sections" :key="section.value" :value="section.value">
858
+ <AccordionHeader>
859
+ <AccordionTrigger>
860
+ {{ section.label }}
861
+ <ChevronDownIcon aria-hidden="true" />
862
+ </AccordionTrigger>
863
+ </AccordionHeader>
864
+ <AccordionPanel>
865
+ <Accordion v-if="section.topics" multiple>
866
+ <AccordionItem v-for="topic in section.topics" :key="topic.value" :value="topic.value">
867
+ <AccordionHeader>
868
+ <template #render="{ props }">
869
+ <h4 v-bind="props">
870
+ <AccordionTrigger>
871
+ {{ topic.label }}
872
+ <ChevronDownIcon aria-hidden="true" />
873
+ </AccordionTrigger>
874
+ </h4>
875
+ </template>
876
+ </AccordionHeader>
877
+ <AccordionPanel>
878
+ {{ topic.content }}
879
+ </AccordionPanel>
880
+ </AccordionItem>
881
+ </Accordion>
882
+ <div v-else>{{ section.content }}</div>
883
+ </AccordionPanel>
884
+ </AccordionItem>
885
+ </Accordion>
886
+ </template>
887
+ ```
888
+
889
+ Open Billing, then Invoices inside it. The inner accordion changes without closing Billing.
890
+
891
+ ## FAQ Search
892
+
893
+ <span id="faq-with-search" />
894
+
895
+ Combine a search field with a controlled accordion: filter the questions and set `value` to the matching items. The example also highlights matches and leaves the triggers usable while the search is active.
896
+
897
+ ```vue title="search.vue"
898
+ <script setup lang="ts">
899
+ import { ChevronDownIcon } from "@lucide/vue"
900
+ import {
901
+ Accordion,
902
+ AccordionHeader,
903
+ AccordionItem,
904
+ AccordionPanel,
905
+ AccordionTrigger,
906
+ } from "@ui-sdk/vue/accordion"
907
+ import { computed, ref } from "vue"
908
+
909
+ const faq = [
910
+ {
911
+ value: "returns",
912
+ question: "What is your return policy?",
913
+ answer:
914
+ "Return any unused item within 30 days. Once it reaches us, your refund is on its way.",
915
+ },
916
+ {
917
+ value: "refunds",
918
+ question: "How long do refunds take?",
919
+ answer:
920
+ "Refunds reach your card within 5 to 7 business days after we receive the item.",
921
+ },
922
+ {
923
+ value: "shipping",
924
+ question: "Do you ship internationally?",
925
+ answer:
926
+ "We ship to 40 countries. Duties are included in the price at checkout.",
927
+ },
928
+ {
929
+ value: "tracking",
930
+ question: "How do I track my order?",
931
+ answer:
932
+ "Every shipping email has a tracking link. You'll also find it under Orders.",
933
+ },
934
+ {
935
+ value: "exchange",
936
+ question: "Can I exchange an item for another size?",
937
+ answer:
938
+ "Yes. Start a return, choose Exchange and pick the new size. Shipping is free.",
939
+ },
940
+ {
941
+ value: "gift",
942
+ question: "Can I send an order as a gift?",
943
+ answer:
944
+ "Add a gift note at checkout and we'll leave the prices off the packing slip.",
945
+ },
946
+ ]
947
+
948
+ function matches(question: (typeof faq)[number], query: string) {
949
+ const search = query.trim().toLowerCase()
950
+ return (
951
+ !search ||
952
+ question.question.toLowerCase().includes(search) ||
953
+ question.answer.toLowerCase().includes(search)
954
+ )
955
+ }
956
+
957
+ function highlight(text: string, query: string) {
958
+ const search = query.trim().toLowerCase()
959
+ if (!search) {
960
+ return [{ text, match: false }]
961
+ }
962
+ const parts: { text: string; match: boolean }[] = []
963
+ let start = 0
964
+ for (let index = text.toLowerCase().indexOf(search); index !== -1;) {
965
+ if (index > start) {
966
+ parts.push({ text: text.slice(start, index), match: false })
967
+ }
968
+ parts.push({ text: text.slice(index, index + search.length), match: true })
969
+ start = index + search.length
970
+ index = text.toLowerCase().indexOf(search, start)
971
+ }
972
+ if (start < text.length) {
973
+ parts.push({ text: text.slice(start), match: false })
974
+ }
975
+ return parts
976
+ }
977
+
978
+ const query = ref("")
979
+ const value = ref<string[]>([])
980
+ const results = computed(() =>
981
+ faq.filter((question) => matches(question, query.value))
982
+ )
983
+
984
+ function search(next: string) {
985
+ query.value = next
986
+ value.value = next.trim()
987
+ ? results.value.map((question) => question.value)
988
+ : []
989
+ }
990
+ </script>
991
+
992
+ <template>
993
+ <div>
994
+ <div data-slot="controls">
995
+ <input
996
+ type="search"
997
+ aria-label="Search questions"
998
+ placeholder="Search questions…"
999
+ :value="query"
1000
+ @input="search(($event.target as HTMLInputElement).value)"
1001
+ />
1002
+ </div>
1003
+ <Accordion v-model:value="value" multiple>
1004
+ <AccordionItem v-for="question in results" :key="question.value" :value="question.value">
1005
+ <AccordionHeader>
1006
+ <AccordionTrigger>
1007
+ <span>
1008
+ <template v-for="(part, index) in highlight(question.question, query)" :key="index">
1009
+ <mark v-if="part.match">{{ part.text }}</mark>
1010
+ <template v-else>{{ part.text }}</template>
1011
+ </template>
1012
+ </span>
1013
+ <ChevronDownIcon aria-hidden="true" />
1014
+ </AccordionTrigger>
1015
+ </AccordionHeader>
1016
+ <AccordionPanel>
1017
+ <template v-for="(part, index) in highlight(question.answer, query)" :key="index">
1018
+ <mark v-if="part.match">{{ part.text }}</mark>
1019
+ <template v-else>{{ part.text }}</template>
1020
+ </template>
1021
+ </AccordionPanel>
1022
+ </AccordionItem>
1023
+ </Accordion>
1024
+ <p data-slot="hint" role="status">
1025
+ <template v-if="results.length === 0"
1026
+ >No questions match “{{ query }}”.</template
1027
+ >
1028
+ </p>
1029
+ </div>
1030
+ </template>
1031
+ ```
1032
+
1033
+ Search for “refund” to show and open matching answers. Try “zzz” for the empty result, then clear the search to restore all questions.
1034
+
1035
+ ## URL Hash
1036
+
1037
+ <span id="open-the-item-in-the-url-hash" />
1038
+
1039
+ A hash can name an item's `value` instead of an element inside its panel. Read it after mount and on `hashchange`, then open and focus the matching item through your controller:
1040
+
1041
+ ```ts
1042
+ const value = decodeURIComponent(location.hash.slice(1))
1043
+ if (items.some((item) => item.value === value)) {
1044
+ accordion.open(value)
1045
+ accordion.focus(value)
1046
+ }
1047
+ ```
1048
+
1049
+ Check the value against your items first. A controller can hold a value even when no item renders it. Remove the `hashchange` listener when the component unmounts.
1050
+
1051
+ ## Query String
1052
+
1053
+ <span id="keep-open-items-in-the-query-string" />
1054
+
1055
+ Use `open` query parameters when several items should be shareable. Read the initial values from your router on the server, then write accepted changes back to the URL:
1056
+
1057
+ ```ts
1058
+ function saveOpenItems(value: string[]) {
1059
+ const url = new URL(location.href)
1060
+ url.searchParams.delete("open")
1061
+ for (const item of value) url.searchParams.append("open", item)
1062
+ history.replaceState(null, "", url)
1063
+ }
1064
+ ```
1065
+
1066
+ Call this from `@value-change` after updating your state. If your app already has a router, use its navigation API instead.
1067
+
1068
+ ## Scroll into View
1069
+
1070
+ <span id="scroll-an-item-into-view" />
1071
+
1072
+ Scroll after `@open-change-complete`, when the panel has its full height. Scrolling in `@open-change` would measure it before it opens. The [Expand All example](#expand-all) shows the full setup and scrolls only when someone opens a single item.
1073
+
1074
+ ## Custom Rendering
1075
+
1076
+ <span id="render-functions" />
1077
+
1078
+ Use a `#render` slot to choose another heading level or element. [Parts and Composition](../parts-and-composition.md#choose-the-element) covers custom elements and part state. Accordion's states are listed under [State](#state).
1079
+
1080
+ ```vue title="render.vue"
1081
+ <script setup lang="ts">
1082
+ import {
1083
+ Accordion,
1084
+ AccordionHeader,
1085
+ AccordionItem,
1086
+ AccordionPanel,
1087
+ AccordionTrigger,
1088
+ } from "@ui-sdk/vue/accordion"
1089
+
1090
+ const steps = [
1091
+ {
1092
+ value: "install",
1093
+ label: "Install the package",
1094
+ content: "Add it with your package manager. It has no dependencies.",
1095
+ },
1096
+ {
1097
+ value: "import",
1098
+ label: "Import the parts",
1099
+ content: "Import the accordion parts you need from the package.",
1100
+ },
1101
+ {
1102
+ value: "style",
1103
+ label: "Style it",
1104
+ content: "Every part renders its state as data attributes you can style.",
1105
+ },
1106
+ ]
1107
+ </script>
1108
+
1109
+ <template>
1110
+ <Accordion multiple :default-value="['install']">
1111
+ <AccordionItem v-for="step in steps" :key="step.value" :value="step.value">
1112
+ <AccordionHeader>
1113
+ <template #render="{ props }">
1114
+ <h4 v-bind="props">
1115
+ <AccordionTrigger>
1116
+ <template #render="{ props: triggerProps, state: triggerState }">
1117
+ <button v-bind="triggerProps">
1118
+ <span
1119
+ data-slot="hint"
1120
+ v-if="triggerState.index >= 0"
1121
+ aria-hidden="true"
1122
+ >
1123
+ {{ String(triggerState.index + 1).padStart(2, "0") }}
1124
+ </span>
1125
+ <span>{{ step.label }}</span>
1126
+ <span data-slot="hint" aria-hidden="true">
1127
+ {{ triggerState.open ? "Hide" : "Show" }}
1128
+ </span>
1129
+ </button>
1130
+ </template>
1131
+ </AccordionTrigger>
1132
+ </h4>
1133
+ </template>
1134
+ </AccordionHeader>
1135
+ <AccordionPanel>
1136
+ {{ step.content }}
1137
+ </AccordionPanel>
1138
+ </AccordionItem>
1139
+ </Accordion>
1140
+ </template>
1141
+ ```
1142
+
1143
+ Each step is an h4 with its number and a Show or Hide hint that follows its open state. Open Import the parts to see it update.
1144
+
1145
+ ## Styling
1146
+
1147
+ Style the parts with the attributes below. This turns the chevron as its panel opens, mirrors it in right to left with `:dir(rtl)`, and dims disabled triggers:
1148
+
1149
+ ```css
1150
+ [data-slot="accordion-trigger"] {
1151
+ & > svg {
1152
+ rotate: -90deg;
1153
+
1154
+ &:dir(rtl) {
1155
+ rotate: 90deg;
1156
+ }
1157
+ }
1158
+
1159
+ &[data-open] > svg {
1160
+ rotate: 0deg;
1161
+ }
1162
+
1163
+ &[data-disabled] {
1164
+ color: gray;
1165
+ }
1166
+ }
1167
+ ```
1168
+
1169
+ ### AccordionPanel
1170
+ - `--accordion-panel-height`: The panel's content height in pixels while it animates, auto once open and 0px while closed.
1171
+ - `--accordion-panel-width`: The panel's content width, the same way. For accordions that open sideways.
1172
+
1173
+ ## Data Attributes
1174
+
1175
+ ### Accordion
1176
+ `[data-slot="accordion"]`
1177
+
1178
+ - `data-disabled`: Present when the whole accordion is disabled.
1179
+
1180
+ ### AccordionItem
1181
+ `[data-slot="accordion-item"]`
1182
+
1183
+ - `data-open`: Present while the item is open.
1184
+ - `data-closed`: Present while the item is closed, including while its panel animates out.
1185
+ - `data-disabled`: Present when the item can't open or close.
1186
+
1187
+ ### AccordionHeader
1188
+ `[data-slot="accordion-header"]`
1189
+
1190
+ - `data-open`: Present while the item is open.
1191
+ - `data-closed`: Present while the item is closed, including while its panel animates out.
1192
+ - `data-disabled`: Present when the item can't open or close.
1193
+
1194
+ ### AccordionTrigger
1195
+ `[data-slot="accordion-trigger"]`
1196
+
1197
+ - `data-open`: Present while the item is open.
1198
+ - `data-closed`: Present while the item is closed, including while its panel animates out.
1199
+ - `data-disabled`: Present when the item can't open or close.
1200
+
1201
+ ### AccordionPanel
1202
+ `[data-slot="accordion-panel"]`
1203
+
1204
+ - `data-open`: Present while the item is open.
1205
+ - `data-closed`: Present while the item is closed, including while its panel animates out.
1206
+ - `data-disabled`: Present when the item can't open or close.
1207
+ - `data-starting-style`: Present for a panel's first frame. Style the state you animate from.
1208
+ - `data-ending-style`: Present while a panel animates closed. Style the state you animate to.
1209
+
1210
+ ## API Reference
1211
+
1212
+ Props are the same as below, and callbacks are events. Headers, triggers and panels take their item's value
1213
+ from the item.
1214
+
1215
+ ### Accordion
1216
+
1217
+ - `value?` (`T[]`): The open items' values. Pass it to control the accordion.
1218
+ - `defaultValue?` (`T[]`): The items open at first, when uncontrolled.
1219
+ - `@value-change` (`((value: T[], details: ChangeDetails<AccordionValueChangeReason>) => void)`): Runs when items want to open or close. `details.reason` says why, and `details.cancel()` stops it.
1220
+ - `multiple?` (`boolean`): Whether several items can be open at once. Otherwise opening one closes the others.
1221
+ - `collapsible?` (`boolean`): Whether the open item can close when only one may be open. With `false`, one item always stays open and its trigger reports it can't be pressed.
1222
+ - `disabled?` (`boolean`): Stops every item from opening or closing. Triggers stay focusable.
1223
+ - `keepMounted?` (`boolean`): Whether closed panels stay in the page, hidden.
1224
+ - `hiddenUntilFound?` (`boolean`): Keeps closed panels in the page as `hidden="until-found"`, so the browser's find in page can match their text and open them.
1225
+ - `controller?` (`object`): Opens and closes items from anywhere. Create one with `createAccordionController()`.
1226
+ - `debug?` (`boolean`): Logs every state change with its reason to the console, in development builds.
1227
+
1228
+ ### AccordionItem
1229
+
1230
+ - `disabled?` (`boolean`): Stops the item from opening or closing. Its trigger stays focusable.
1231
+ - `@open-change` (`((open: boolean, details: ChangeDetails<AccordionValueChangeReason>) => void)`): Runs before the item opens or closes, before the accordion's `@value-change`. `details.cancel()` stops it.
1232
+ - `@open-change-complete` (`((open: boolean) => void)`): Runs once the item's panel has finished opening or closing, after any animation.
1233
+ - `value?` (`T`): Identifies the item. The accordion's value lists the open items' values. Defaults to a generated id.
1234
+
1235
+ ### AccordionHeader
1236
+
1237
+ The header takes no options of its own, only the props of the element it renders.
1238
+
1239
+ ### AccordionTrigger
1240
+
1241
+ - `disabled?` (`boolean`): Stops this trigger from opening or closing the item. It stays focusable.
1242
+
1243
+ ### AccordionPanel
1244
+
1245
+ - `keepMounted?` (`boolean`): Whether the panel stays in the page, hidden, while closed. Overrides the accordion's.
1246
+ - `hiddenUntilFound?` (`boolean`): Whether the panel stays findable with `hidden="until-found"` while closed. Overrides the accordion's.
1247
+ ### State
1248
+
1249
+ What render functions, state-based class names and slots receive, per part.
1250
+
1251
+ `Accordion`:
1252
+
1253
+ - `value` (`T[]`): The open items' values.
1254
+ - `disabled` (`boolean`): Whether the whole accordion is disabled, by its `disabled` option or a disabled fieldset around it.
1255
+ - `multiple` (`boolean`): Whether several items can be open at once.
1256
+
1257
+ `AccordionItem`, `AccordionHeader`, `AccordionTrigger` and `AccordionPanel`:
1258
+
1259
+ - `open` (`boolean`): Whether the accordion's `value` holds this item's value.
1260
+ - `disabled` (`boolean`): Whether the item can't open or close.
1261
+ - `index` (`number`): The item's position among the accordion's items, from 0. -1 until it's in the page.
1262
+
1263
+ ### Reasons
1264
+
1265
+ `details.reason` says why items opened or closed, for `@value-change` and every item's `@open-change`.
1266
+
1267
+ - `trigger-press` (`MouseEvent | KeyboardEvent | TouchEvent`): Click, tap, Enter or Space on the part that opens, closes or toggles. Arrow keys that open a menu or submenu count too. A tap on a combobox's input that opens a sheet reports its `touchend`.
1268
+ - `find-in-page` (`Event`): The browser's find in page matched hidden content.
1269
+ - `imperative` (`none`): A controller or `api` call, or a property set on a web component.
1270
+
1271
+ ### Controller
1272
+
1273
+ Create one with `createAccordionController()` and pass it as `controller`.
1274
+
1275
+ Every write method takes an optional `{ reason, event }`, runs the item and accordion callbacks like a press, and returns `false` when the change is canceled or does nothing.
1276
+
1277
+ - `getValue()` (`() => T[]`): The open items' values.
1278
+ - `setValue(value, options?)` (`(value: T[], options?: AccordionChangeOptions | undefined) => boolean`): Sets the open items. Only the first counts unless `multiple` is set. Returns false when canceled.
1279
+ - `isOpen(value)` (`(value: T) => boolean`): Whether an item is open.
1280
+ - `open(value, options?)` (`(value: T, options?: AccordionChangeOptions | undefined) => boolean`): Opens an item. With one item open at a time, closes the others.
1281
+ - `close(value, options?)` (`(value: T, options?: AccordionChangeOptions | undefined) => boolean`): Closes an item, unless it's the one item that must stay open.
1282
+ - `toggle(value, options?)` (`(value: T, options?: AccordionChangeOptions | undefined) => boolean`): Opens a closed item, or closes an open one.
1283
+ - `openAll(options?)` (`(options?: AccordionChangeOptions | undefined) => boolean`): Opens every enabled item. Only when `multiple` is set.
1284
+ - `closeAll(options?)` (`(options?: AccordionChangeOptions | undefined) => boolean`): Closes every item that may close.
1285
+ - `focus(value?)` (`(value?: T | undefined) => void`): Moves focus to an item's trigger, or the first trigger.
1286
+
1287
+ ### Events
1288
+
1289
+ Events get the new state first, then the details.
1290
+
1291
+ | Binding | On | Receives |
1292
+ | ----------------------- | --------------- | -------------------------------------------------------------- |
1293
+ | `v-model:value` | `Accordion` | The open items |
1294
+ | `@value-change` | `Accordion` | `(value, details)`: the open items, and the [reason](#reasons) |
1295
+ | `@open-change` | `AccordionItem` | `(open, details)`, before `@value-change` |
1296
+ | `@open-change-complete` | `AccordionItem` | `(open)`, after the panel's animation |
1297
+
1298
+ ## Accessibility
1299
+
1300
+ The accordion follows the [WAI-ARIA accordion pattern](https://www.w3.org/WAI/ARIA/apg/patterns/accordion/). Every line below is an automated test.
1301
+
1302
+ **Expanding and collapsing**
1303
+
1304
+ - The default item is expanded and shows its panel.
1305
+ - Clicking a collapsed trigger expands it and collapses the open one.
1306
+ - Clicking an expanded trigger collapses it.
1307
+ - Clicking a disabled trigger does nothing.
1308
+ - A change can be canceled.
1309
+ - Without a default value, every item starts collapsed.
1310
+ - A default value can expand several items.
1311
+
1312
+ **Multiple**
1313
+
1314
+ - Items expand and collapse independently.
1315
+ - Every item can be expanded at once.
1316
+
1317
+ **Disabled**
1318
+
1319
+ - A disabled item's trigger is marked disabled and stays focusable.
1320
+ - A disabled accordion disables every trigger.
1321
+
1322
+ **Keyboard**
1323
+
1324
+ - Tab moves through every trigger in order, disabled ones included.
1325
+ - Enter toggles the focused trigger's panel.
1326
+ - Space toggles the focused trigger's panel.
1327
+ - Enter on a disabled trigger does nothing.
1328
+ - Tab moves from an expanded trigger into its panel.
1329
+ - Keys pressed in quick succession are never lost.
1330
+ - Arrow keys leave focus where it is.
1331
+
1332
+ **Structure**
1333
+
1334
+ - Each trigger sits in a heading.
1335
+ - The trigger controls its panel, and the panel is labelled by its trigger.
1336
+
1337
+ **Mounting**
1338
+
1339
+ - Collapsed panels leave the page by default.
1340
+ - With keepMounted, collapsed panels stay in the page, hidden.
1341
+ - With keepMounted, a class that sets display doesn't show collapsed panels.
1342
+ - With hiddenUntilFound, collapsed panels stay findable.
1343
+ - Finding text in a collapsed panel expands it.
1344
+ - Following a link into a collapsed panel expands it.
1345
+ - The browser's own find expands a collapsed panel.
1346
+
1347
+ Runs in React, Vue and web components.
1348
+
1349
+ Beyond the pattern's baseline:
1350
+
1351
+ **Enhancements**
1352
+
1353
+ - With collapsible off, the open trigger is marked disabled and stays open.
1354
+ - Closing a panel that holds focus moves focus to its trigger.
1355
+ - A canceled find in page keeps the panel hidden until found.
1356
+ - An infinite exit animation still unmounts the panel.
1357
+ - A controller expands and collapses items from anywhere.
1358
+ - An item's onOpenChangeComplete runs once its panel has finished animating.
1359
+ - Find in page opens a panel at once, without an animation.
1360
+
1361
+ Runs in React, Vue and web components.
1362
+
1363
+ Every panel is a region labelled by its trigger, so screen readers can list open panels as landmarks. With many panels open at once, such as `multiple` with Expand all, keep the number of items modest so that list stays short.
1364
+
1365
+ Screen readers hear the same thing in each tested framework, recorded by a virtual screen reader:
1366
+
1367
+ - Announcements while using the accordion with a keyboard.
1368
+
1369
+ Runs in React, Vue and web components.