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