@funstack/ui 0.1.0-alpha.19 → 0.1.0-alpha.20

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 (276) hide show
  1. package/dist/accordion/accordion-item.mjs +2 -2
  2. package/dist/accordion/accordion-item.mjs.map +1 -1
  3. package/dist/accordion/accordion-trigger.d.mts.map +1 -1
  4. package/dist/accordion/accordion-trigger.mjs +3 -20
  5. package/dist/accordion/accordion-trigger.mjs.map +1 -1
  6. package/dist/alert-dialog/alert-dialog-action.d.mts +73 -0
  7. package/dist/alert-dialog/alert-dialog-action.d.mts.map +1 -0
  8. package/dist/alert-dialog/alert-dialog-action.mjs +23 -0
  9. package/dist/alert-dialog/alert-dialog-action.mjs.map +1 -0
  10. package/dist/alert-dialog/alert-dialog-cancel.d.mts +31 -0
  11. package/dist/alert-dialog/alert-dialog-cancel.d.mts.map +1 -0
  12. package/dist/alert-dialog/alert-dialog-cancel.mjs +50 -0
  13. package/dist/alert-dialog/alert-dialog-cancel.mjs.map +1 -0
  14. package/dist/alert-dialog/alert-dialog-context.mjs +24 -0
  15. package/dist/alert-dialog/alert-dialog-context.mjs.map +1 -0
  16. package/dist/alert-dialog/alert-dialog-description.d.mts +25 -0
  17. package/dist/alert-dialog/alert-dialog-description.d.mts.map +1 -0
  18. package/dist/alert-dialog/alert-dialog-description.mjs +20 -0
  19. package/dist/alert-dialog/alert-dialog-description.mjs.map +1 -0
  20. package/dist/alert-dialog/alert-dialog-form.d.mts +27 -0
  21. package/dist/alert-dialog/alert-dialog-form.d.mts.map +1 -0
  22. package/dist/alert-dialog/alert-dialog-form.mjs +22 -0
  23. package/dist/alert-dialog/alert-dialog-form.mjs.map +1 -0
  24. package/dist/alert-dialog/alert-dialog-popup.d.mts +42 -0
  25. package/dist/alert-dialog/alert-dialog-popup.d.mts.map +1 -0
  26. package/dist/alert-dialog/alert-dialog-popup.mjs +53 -0
  27. package/dist/alert-dialog/alert-dialog-popup.mjs.map +1 -0
  28. package/dist/alert-dialog/alert-dialog-root.d.mts +31 -0
  29. package/dist/alert-dialog/alert-dialog-root.d.mts.map +1 -0
  30. package/dist/alert-dialog/alert-dialog-root.mjs +22 -0
  31. package/dist/alert-dialog/alert-dialog-root.mjs.map +1 -0
  32. package/dist/alert-dialog/alert-dialog-title.d.mts +23 -0
  33. package/dist/alert-dialog/alert-dialog-title.d.mts.map +1 -0
  34. package/dist/alert-dialog/alert-dialog-title.mjs +18 -0
  35. package/dist/alert-dialog/alert-dialog-title.mjs.map +1 -0
  36. package/dist/alert-dialog/alert-dialog-trigger.d.mts +23 -0
  37. package/dist/alert-dialog/alert-dialog-trigger.d.mts.map +1 -0
  38. package/dist/alert-dialog/alert-dialog-trigger.mjs +18 -0
  39. package/dist/alert-dialog/alert-dialog-trigger.mjs.map +1 -0
  40. package/dist/alert-dialog/index.d.mts +33 -0
  41. package/dist/alert-dialog/index.d.mts.map +1 -0
  42. package/dist/alert-dialog/index.mjs +33 -0
  43. package/dist/alert-dialog/index.mjs.map +1 -0
  44. package/dist/checkbox-group/checkbox-group-parent.mjs +1 -1
  45. package/dist/collapsible/collapsible-context.mjs +8 -0
  46. package/dist/collapsible/collapsible-context.mjs.map +1 -0
  47. package/dist/collapsible/collapsible-panel.d.mts +53 -0
  48. package/dist/collapsible/collapsible-panel.d.mts.map +1 -0
  49. package/dist/collapsible/collapsible-panel.mjs +41 -0
  50. package/dist/collapsible/collapsible-panel.mjs.map +1 -0
  51. package/dist/collapsible/collapsible-root.d.mts +108 -0
  52. package/dist/collapsible/collapsible-root.d.mts.map +1 -0
  53. package/dist/collapsible/collapsible-root.mjs +147 -0
  54. package/dist/collapsible/collapsible-root.mjs.map +1 -0
  55. package/dist/collapsible/collapsible-trigger.d.mts +45 -0
  56. package/dist/collapsible/collapsible-trigger.d.mts.map +1 -0
  57. package/dist/collapsible/collapsible-trigger.mjs +62 -0
  58. package/dist/collapsible/collapsible-trigger.mjs.map +1 -0
  59. package/dist/collapsible/index.d.mts +21 -0
  60. package/dist/collapsible/index.d.mts.map +1 -0
  61. package/dist/collapsible/index.mjs +21 -0
  62. package/dist/collapsible/index.mjs.map +1 -0
  63. package/dist/combobox/chip-text.mjs +24 -0
  64. package/dist/combobox/chip-text.mjs.map +1 -0
  65. package/dist/combobox/combobox-chips.d.mts +159 -0
  66. package/dist/combobox/combobox-chips.d.mts.map +1 -0
  67. package/dist/combobox/combobox-chips.mjs +198 -0
  68. package/dist/combobox/combobox-chips.mjs.map +1 -0
  69. package/dist/combobox/combobox-clear.d.mts +5 -2
  70. package/dist/combobox/combobox-clear.d.mts.map +1 -1
  71. package/dist/combobox/combobox-clear.mjs +3 -1
  72. package/dist/combobox/combobox-clear.mjs.map +1 -1
  73. package/dist/combobox/combobox-context.mjs +4 -5
  74. package/dist/combobox/combobox-context.mjs.map +1 -1
  75. package/dist/combobox/combobox-input.d.mts +10 -3
  76. package/dist/combobox/combobox-input.d.mts.map +1 -1
  77. package/dist/combobox/combobox-input.mjs +13 -5
  78. package/dist/combobox/combobox-input.mjs.map +1 -1
  79. package/dist/combobox/combobox-keyboard.mjs +50 -4
  80. package/dist/combobox/combobox-keyboard.mjs.map +1 -1
  81. package/dist/combobox/combobox-list.d.mts +1 -1
  82. package/dist/combobox/combobox-list.mjs +2 -1
  83. package/dist/combobox/combobox-list.mjs.map +1 -1
  84. package/dist/combobox/combobox-option.d.mts +5 -2
  85. package/dist/combobox/combobox-option.d.mts.map +1 -1
  86. package/dist/combobox/combobox-option.mjs +4 -3
  87. package/dist/combobox/combobox-option.mjs.map +1 -1
  88. package/dist/combobox/combobox-root.d.mts +127 -35
  89. package/dist/combobox/combobox-root.d.mts.map +1 -1
  90. package/dist/combobox/combobox-root.mjs +396 -44
  91. package/dist/combobox/combobox-root.mjs.map +1 -1
  92. package/dist/combobox/index.d.mts +8 -2
  93. package/dist/combobox/index.d.mts.map +1 -1
  94. package/dist/combobox/index.mjs +7 -1
  95. package/dist/combobox/index.mjs.map +1 -1
  96. package/dist/combobox/use-combobox-form.mjs +2 -3
  97. package/dist/combobox/use-combobox-form.mjs.map +1 -1
  98. package/dist/dialog/dialog-close.d.mts +9 -5
  99. package/dist/dialog/dialog-close.d.mts.map +1 -1
  100. package/dist/dialog/dialog-close.mjs +19 -8
  101. package/dist/dialog/dialog-close.mjs.map +1 -1
  102. package/dist/dialog/dialog-context.d.mts +2 -0
  103. package/dist/dialog/dialog-context.mjs +14 -2
  104. package/dist/dialog/dialog-context.mjs.map +1 -1
  105. package/dist/dialog/dialog-description.d.mts +2 -1
  106. package/dist/dialog/dialog-description.d.mts.map +1 -1
  107. package/dist/dialog/dialog-description.mjs +8 -4
  108. package/dist/dialog/dialog-description.mjs.map +1 -1
  109. package/dist/dialog/dialog-form.d.mts +2 -1
  110. package/dist/dialog/dialog-form.d.mts.map +1 -1
  111. package/dist/dialog/dialog-form.mjs +11 -6
  112. package/dist/dialog/dialog-form.mjs.map +1 -1
  113. package/dist/dialog/dialog-popup.d.mts +2 -1
  114. package/dist/dialog/dialog-popup.d.mts.map +1 -1
  115. package/dist/dialog/dialog-popup.mjs +23 -14
  116. package/dist/dialog/dialog-popup.mjs.map +1 -1
  117. package/dist/dialog/dialog-root.d.mts +2 -1
  118. package/dist/dialog/dialog-root.d.mts.map +1 -1
  119. package/dist/dialog/dialog-root.mjs +15 -5
  120. package/dist/dialog/dialog-root.mjs.map +1 -1
  121. package/dist/dialog/dialog-title.d.mts +2 -1
  122. package/dist/dialog/dialog-title.d.mts.map +1 -1
  123. package/dist/dialog/dialog-title.mjs +8 -4
  124. package/dist/dialog/dialog-title.mjs.map +1 -1
  125. package/dist/dialog/dialog-trigger.d.mts +2 -1
  126. package/dist/dialog/dialog-trigger.d.mts.map +1 -1
  127. package/dist/dialog/dialog-trigger.mjs +14 -9
  128. package/dist/dialog/dialog-trigger.mjs.map +1 -1
  129. package/dist/docs/components/accordion.md +2 -0
  130. package/dist/docs/components/alert-dialog.md +546 -0
  131. package/dist/docs/components/collapsible.md +408 -0
  132. package/dist/docs/components/combobox.md +288 -26
  133. package/dist/docs/components/dialog.md +7 -5
  134. package/dist/docs/components/field.md +180 -3
  135. package/dist/docs/components/hover-card.md +494 -0
  136. package/dist/docs/components/multi-select.md +622 -0
  137. package/dist/docs/components/number-field.md +1 -1
  138. package/dist/docs/components/popover.md +4 -4
  139. package/dist/docs/components/select.md +9 -1
  140. package/dist/docs/components/separator.md +182 -0
  141. package/dist/docs/components/slider.md +1 -1
  142. package/dist/docs/components/tooltip.md +1 -1
  143. package/dist/docs/concepts/experimental.md +3 -3
  144. package/dist/docs/concepts/server-components.md +1 -1
  145. package/dist/docs/index.md +7 -2
  146. package/dist/docs/roadmap.md +8 -0
  147. package/dist/field/field-control.d.mts +13 -4
  148. package/dist/field/field-control.d.mts.map +1 -1
  149. package/dist/field/field-control.mjs +39 -10
  150. package/dist/field/field-control.mjs.map +1 -1
  151. package/dist/field/field-label.d.mts +6 -2
  152. package/dist/field/field-label.d.mts.map +1 -1
  153. package/dist/field/field-label.mjs +12 -2
  154. package/dist/field/field-label.mjs.map +1 -1
  155. package/dist/field/field-root.mjs +9 -1
  156. package/dist/field/field-root.mjs.map +1 -1
  157. package/dist/hover-card/hover-card-context.mjs +13 -0
  158. package/dist/hover-card/hover-card-context.mjs.map +1 -0
  159. package/dist/hover-card/hover-card-popup.d.mts +102 -0
  160. package/dist/hover-card/hover-card-popup.d.mts.map +1 -0
  161. package/dist/hover-card/hover-card-popup.mjs +80 -0
  162. package/dist/hover-card/hover-card-popup.mjs.map +1 -0
  163. package/dist/hover-card/hover-card-root.d.mts +94 -0
  164. package/dist/hover-card/hover-card-root.d.mts.map +1 -0
  165. package/dist/hover-card/hover-card-root.mjs +74 -0
  166. package/dist/hover-card/hover-card-root.mjs.map +1 -0
  167. package/dist/hover-card/hover-card-trigger.d.mts +65 -0
  168. package/dist/hover-card/hover-card-trigger.d.mts.map +1 -0
  169. package/dist/hover-card/hover-card-trigger.mjs +109 -0
  170. package/dist/hover-card/hover-card-trigger.mjs.map +1 -0
  171. package/dist/hover-card/index.d.mts +24 -0
  172. package/dist/hover-card/index.d.mts.map +1 -0
  173. package/dist/hover-card/index.mjs +24 -0
  174. package/dist/hover-card/index.mjs.map +1 -0
  175. package/dist/hover-card/use-hover-card-interest.mjs +242 -0
  176. package/dist/hover-card/use-hover-card-interest.mjs.map +1 -0
  177. package/dist/index.d.mts +38 -9
  178. package/dist/index.mjs +6 -1
  179. package/dist/internal/action/use-multiple-selection.mjs +83 -0
  180. package/dist/internal/action/use-multiple-selection.mjs.map +1 -0
  181. package/dist/internal/details-summary.mjs +56 -0
  182. package/dist/internal/details-summary.mjs.map +1 -0
  183. package/dist/internal/form/field-context.mjs.map +1 -1
  184. package/dist/internal/form/hidden-values.mjs +29 -0
  185. package/dist/internal/form/hidden-values.mjs.map +1 -0
  186. package/dist/internal/form/validity.mjs +3 -1
  187. package/dist/internal/form/validity.mjs.map +1 -1
  188. package/dist/internal/overlay/use-interest-dismiss.mjs +2 -1
  189. package/dist/internal/overlay/use-interest-dismiss.mjs.map +1 -1
  190. package/dist/internal/overlay/use-overlay-close.mjs +5 -3
  191. package/dist/internal/overlay/use-overlay-close.mjs.map +1 -1
  192. package/dist/internal/overlay/use-overlay-root.mjs +4 -1
  193. package/dist/internal/overlay/use-overlay-root.mjs.map +1 -1
  194. package/dist/internal/overlay/use-popover-popup.mjs +20 -7
  195. package/dist/internal/overlay/use-popover-popup.mjs.map +1 -1
  196. package/dist/internal/overlay/use-popover-trigger.d.mts +1 -1
  197. package/dist/internal/typeahead.mjs +52 -0
  198. package/dist/internal/typeahead.mjs.map +1 -0
  199. package/dist/{combobox → internal}/use-active-option.mjs +8 -6
  200. package/dist/internal/use-active-option.mjs.map +1 -0
  201. package/dist/{combobox → internal}/use-deferred-leave.mjs +20 -12
  202. package/dist/internal/use-deferred-leave.mjs.map +1 -0
  203. package/dist/internal/use-name-warning.mjs +57 -1
  204. package/dist/internal/use-name-warning.mjs.map +1 -1
  205. package/dist/internal/use-option-registry.mjs +70 -0
  206. package/dist/internal/use-option-registry.mjs.map +1 -0
  207. package/dist/menu/use-menu-keyboard.mjs +7 -27
  208. package/dist/menu/use-menu-keyboard.mjs.map +1 -1
  209. package/dist/multi-select/index.d.mts +37 -0
  210. package/dist/multi-select/index.d.mts.map +1 -0
  211. package/dist/multi-select/index.mjs +37 -0
  212. package/dist/multi-select/index.mjs.map +1 -0
  213. package/dist/multi-select/multi-select-context.mjs +19 -0
  214. package/dist/multi-select/multi-select-context.mjs.map +1 -0
  215. package/dist/multi-select/multi-select-group.d.mts +120 -0
  216. package/dist/multi-select/multi-select-group.d.mts.map +1 -0
  217. package/dist/multi-select/multi-select-group.mjs +111 -0
  218. package/dist/multi-select/multi-select-group.mjs.map +1 -0
  219. package/dist/multi-select/multi-select-keyboard.mjs +145 -0
  220. package/dist/multi-select/multi-select-keyboard.mjs.map +1 -0
  221. package/dist/multi-select/multi-select-label.d.mts +42 -0
  222. package/dist/multi-select/multi-select-label.d.mts.map +1 -0
  223. package/dist/multi-select/multi-select-label.mjs +41 -0
  224. package/dist/multi-select/multi-select-label.mjs.map +1 -0
  225. package/dist/multi-select/multi-select-list.d.mts +47 -0
  226. package/dist/multi-select/multi-select-list.d.mts.map +1 -0
  227. package/dist/multi-select/multi-select-list.mjs +65 -0
  228. package/dist/multi-select/multi-select-list.mjs.map +1 -0
  229. package/dist/multi-select/multi-select-option.d.mts +68 -0
  230. package/dist/multi-select/multi-select-option.d.mts.map +1 -0
  231. package/dist/multi-select/multi-select-option.mjs +93 -0
  232. package/dist/multi-select/multi-select-option.mjs.map +1 -0
  233. package/dist/multi-select/multi-select-popup.d.mts +58 -0
  234. package/dist/multi-select/multi-select-popup.d.mts.map +1 -0
  235. package/dist/multi-select/multi-select-popup.mjs +71 -0
  236. package/dist/multi-select/multi-select-popup.mjs.map +1 -0
  237. package/dist/multi-select/multi-select-root.d.mts +125 -0
  238. package/dist/multi-select/multi-select-root.d.mts.map +1 -0
  239. package/dist/multi-select/multi-select-root.mjs +257 -0
  240. package/dist/multi-select/multi-select-root.mjs.map +1 -0
  241. package/dist/multi-select/multi-select-trigger.d.mts +66 -0
  242. package/dist/multi-select/multi-select-trigger.d.mts.map +1 -0
  243. package/dist/multi-select/multi-select-trigger.mjs +169 -0
  244. package/dist/multi-select/multi-select-trigger.mjs.map +1 -0
  245. package/dist/multi-select/multi-select-value.d.mts +57 -0
  246. package/dist/multi-select/multi-select-value.d.mts.map +1 -0
  247. package/dist/multi-select/multi-select-value.mjs +41 -0
  248. package/dist/multi-select/multi-select-value.mjs.map +1 -0
  249. package/dist/number-field/number-field-root.mjs +1 -1
  250. package/dist/number-field/use-step-button.d.mts.map +1 -1
  251. package/dist/number-field/use-step-button.mjs +11 -2
  252. package/dist/number-field/use-step-button.mjs.map +1 -1
  253. package/dist/popover/popover-close.d.mts +6 -3
  254. package/dist/popover/popover-close.d.mts.map +1 -1
  255. package/dist/popover/popover-close.mjs +3 -2
  256. package/dist/popover/popover-close.mjs.map +1 -1
  257. package/dist/popover/popover-popup.mjs +1 -1
  258. package/dist/select/select-root.d.mts +1 -1
  259. package/dist/select/select-root.d.mts.map +1 -1
  260. package/dist/select/select-root.mjs +5 -1
  261. package/dist/select/select-root.mjs.map +1 -1
  262. package/dist/separator/index.d.mts +3 -0
  263. package/dist/separator/index.mjs +1 -0
  264. package/dist/separator/separator.d.mts +58 -0
  265. package/dist/separator/separator.d.mts.map +1 -0
  266. package/dist/separator/separator.mjs +41 -0
  267. package/dist/separator/separator.mjs.map +1 -0
  268. package/dist/slider/slider-root.mjs +1 -0
  269. package/dist/slider/slider-root.mjs.map +1 -1
  270. package/dist/toast/toast-viewport.mjs +1 -1
  271. package/package.json +6 -1
  272. package/skills/funstack-ui-knowledge/SKILL.md +14 -9
  273. package/dist/combobox/use-active-option.mjs.map +0 -1
  274. package/dist/combobox/use-deferred-leave.mjs.map +0 -1
  275. package/dist/combobox/use-option-registry.mjs +0 -52
  276. package/dist/combobox/use-option-registry.mjs.map +0 -1
@@ -0,0 +1,408 @@
1
+ # Collapsible
2
+
3
+ One show/hide region: the Root _is_ the `<details>` and the Trigger its `<summary>`. Without open props its behaviour needs no JavaScript (the parts still ship as client modules; see [Server Components](../concepts/server-components.md)); with them it becomes a regular [state owner](../concepts/pending-and-optimistic.md#state-owner) with actions, optimistic `data-open` and lazily mounted content. For a set of disclosures with arrow-key navigation or one-open-at-a-time, use [Accordion](accordion.md).
4
+
5
+ ```tsx title="CollapsibleSpoiler.tsx"
6
+ // No "use client": this file is a Server Component. The Collapsible has none of `open`,
7
+ // `defaultOpen` and `openChangeAction`, so it runs in JS-free mode: the browser owns
8
+ // <details open>, and opening it works before hydration (and with JavaScript off).
9
+ import { Collapsible } from "@funstack/ui/collapsible";
10
+
11
+ export function CollapsibleSpoiler() {
12
+ return (
13
+ <Collapsible.Root className="demo-collapsible">
14
+ <Collapsible.Trigger className="demo-collapsible-trigger">
15
+ How does the story end?
16
+ </Collapsible.Trigger>
17
+ <Collapsible.Panel className="demo-collapsible-panel">
18
+ <p>
19
+ The zeppelin lands safely. Closed content stays in the page: search for the word zeppelin
20
+ with your browser's find-in-page and it opens by itself.
21
+ </p>
22
+ </Collapsible.Panel>
23
+ </Collapsible.Root>
24
+ );
25
+ }
26
+ ```
27
+
28
+ ```css title="collapsible.css"
29
+ /* Collapsible: the Root is the <details>. `:open` is committed state (both modes);
30
+ [data-open] is optimistic state (library mode only). */
31
+ .demo-collapsible {
32
+ border: 1px solid var(--color-border);
33
+ border-radius: 8px;
34
+ overflow: hidden;
35
+ }
36
+
37
+ .demo-collapsible-trigger {
38
+ display: flex;
39
+ align-items: center;
40
+ gap: 0.6em;
41
+ padding: 0.6em 0.9em;
42
+ cursor: pointer;
43
+ font-weight: 600;
44
+ list-style: none; /* hides the UA marker; the chevron below replaces it */
45
+ }
46
+
47
+ .demo-collapsible-trigger::-webkit-details-marker {
48
+ display: none;
49
+ }
50
+
51
+ .demo-collapsible-trigger:focus-visible {
52
+ outline: 2px solid var(--color-primary);
53
+ outline-offset: -2px;
54
+ }
55
+
56
+ .demo-collapsible-trigger[data-pending] {
57
+ cursor: progress;
58
+ }
59
+
60
+ .demo-collapsible-trigger[data-disabled] {
61
+ color: GrayText;
62
+ cursor: not-allowed;
63
+ }
64
+
65
+ /* Chevron. While pending, the optimistic attribute alone decides, so closing flips the chevron
66
+ at once instead of waiting for :open to go. */
67
+ .demo-collapsible-trigger::before {
68
+ content: "";
69
+ inline-size: 0.5em;
70
+ block-size: 0.5em;
71
+ border-inline-end: 2px solid currentColor;
72
+ border-block-end: 2px solid currentColor;
73
+ rotate: -45deg;
74
+ transition: rotate 150ms;
75
+ }
76
+
77
+ .demo-collapsible:open > .demo-collapsible-trigger:not([data-pending])::before,
78
+ .demo-collapsible-trigger[data-open]::before {
79
+ rotate: 45deg;
80
+ }
81
+
82
+ /* Open/close animation on ::details-content (grid-rows form, every engine, both modes). */
83
+ .demo-collapsible::details-content {
84
+ display: grid;
85
+ grid-template-rows: 0fr;
86
+ transition:
87
+ grid-template-rows 200ms ease,
88
+ content-visibility 200ms allow-discrete;
89
+ }
90
+
91
+ .demo-collapsible:open::details-content {
92
+ grid-template-rows: 1fr;
93
+ }
94
+
95
+ .demo-collapsible-panel {
96
+ min-height: 0; /* the grid item */
97
+ overflow: hidden;
98
+ padding: 0 0.9em;
99
+ }
100
+
101
+ .demo-collapsible-panel :is(p, ul) {
102
+ margin: 0 0 0.8em;
103
+ }
104
+
105
+ @media (prefers-reduced-motion: reduce) {
106
+ .demo-collapsible::details-content,
107
+ .demo-collapsible-trigger::before {
108
+ transition: none;
109
+ }
110
+ }
111
+ ```
112
+
113
+ ## Anatomy
114
+
115
+ ```tsx
116
+ import { Collapsible } from "@funstack/ui/collapsible";
117
+
118
+ <Collapsible.Root> {/* details: state and the transition */}
119
+ <Collapsible.Trigger> {/* summary: must be the Root's first child */}
120
+ Advanced options
121
+ </Collapsible.Trigger>
122
+ <Collapsible.Panel> {/* div: the content */}
123
+ ...
124
+ </Collapsible.Panel>
125
+ </Collapsible.Root>
126
+ ```
127
+
128
+ There is one Trigger and it must be the first child of the Root: that is where the platform puts a `<summary>`. A trigger placed after the content or outside the Root is not possible; drive the Collapsible from elsewhere with controlled `open` instead ([recipe](#recipes)). A heading may go inside the Trigger. If you use `render`, the Root must still render a `<details>` and the Trigger a `<summary>` (development warning otherwise).
129
+
130
+ ## How it works
131
+
132
+ ### Two modes
133
+
134
+ | | JS-free mode | Library mode |
135
+ | - | - | - |
136
+ | Selected when | Root has none of `open`, `defaultOpen`, `openChangeAction` | Root has any of them (`defaultOpen={false}` included) |
137
+ | Open state owner | the browser | React (committed state) |
138
+ | Initial open | closed | `defaultOpen` / `open` |
139
+ | `data-open`, `data-pending` | not emitted; style with `:open` | emitted (optimistic) |
140
+ | Works before hydration | yes, fully | yes; reconciled on mount |
141
+ | `transition` | no effect (development warning) | animates the commit that ends an action |
142
+
143
+ A Collapsible that starts open is in library mode: `defaultOpen` selects it. The HTML is the same `<details open>` and it toggles natively before hydration; after hydration the toggle runs through the Root's transition, which with no action commits at once. See [Browser-owned state](../concepts/browser-owned-state.md) for the reasoning. Switching modes after mount is not supported.
144
+
145
+ ## Props
146
+
147
+ ### `Collapsible.Root`
148
+
149
+ | Prop | Type | Default | Description |
150
+ | - | - | - | - |
151
+ | `open` | `boolean` | – | Controlled open state. undefined means uncontrolled. Selects library mode. |
152
+ | `defaultOpen` | `boolean` | `none (JS-free mode)` | Initial open state, uncontrolled; read once. Its presence selects library mode, false included. Library mode without it (open or openChangeAction only) starts closed, as false. |
153
+ | `openChangeAction` | `ChangeAction<boolean, CollapsibleOpenChangeDetails>` | – | Called with the next open state on every change, inside the Root's transition. Sync, async or a Server Function. `details.reason` (a `ChangeReason`) is `"activate"` for the Trigger, or `"platform"` when the browser opened or closed the `<details>` itself. There is no `onOpenChange`: every change is a request. Selects library mode. |
154
+ | `disabled` | `boolean` | `false` | The Trigger gets aria-disabled="true" and never toggles. Enforced by a click handler, so in JS-free mode it does not hold before hydration. |
155
+ | `experimental_interpolateSize` | `boolean` | `false` | Sets `interpolate-size: allow-keywords` on the `<details>` so `::details-content` can transition `height` to `auto`. Chromium only today; merged under your `style`. Both modes. |
156
+ | `transition` | `ViewTransitionClass` | – | Library mode only. Forwarded to the \<ViewTransition> around the \<details>; animates the open/close commit. |
157
+ | `className` | `string \| ((state: CollapsibleRootState) => string \| undefined)` | – | A class name, or a function of the part's state. |
158
+ | `style` | `CSSProperties \| ((state: CollapsibleRootState) => CSSProperties \| undefined)` | – | Inline style, or a function of the part's state. |
159
+ | `children` | `ReactNode \| ((state: CollapsibleRootState) => ReactNode)` | – | Content, or a function of the Root's state. The Trigger must come first. |
160
+ | `render` | `ReactElement \| ((props, state: CollapsibleRootState) => ReactNode)` | – | Replace the default \<details> (element form) or take over rendering (function form). |
161
+
162
+ - **State**: `CollapsibleRootState` is `{ open, pending, disabled }`; `open` is optimistic, and `undefined` in JS-free mode (the browser owns it).
163
+ - **Owned**: `open`, `name`, `suppressHydrationWarning`, `data-open`, `data-pending`, `data-disabled`, and `onToggle` in library mode.
164
+
165
+ ### `Collapsible.Trigger`
166
+
167
+ | Prop | Type | Default | Description |
168
+ | - | - | - | - |
169
+ | `transition` | `ViewTransitionClass` | – | Library mode only. Animates the commit that ends an action (for example a spinner disappearing), not the optimistic data-open flip. |
170
+ | `className` | `string \| ((state: CollapsibleTriggerState) => string \| undefined)` | – | A class name, or a function of the part's state. |
171
+ | `style` | `CSSProperties \| ((state: CollapsibleTriggerState) => CSSProperties \| undefined)` | – | Inline style, or a function of the part's state. |
172
+ | `children` | `ReactNode \| ((state: CollapsibleTriggerState) => ReactNode)` | – | Rendered from optimistic state; must not suspend. |
173
+ | `render` | `ReactElement \| ((props, state: CollapsibleTriggerState) => ReactNode)` | – | Replace the default \<summary> (element form) or take over rendering (function form). |
174
+
175
+ - **State**: `CollapsibleTriggerState` is the Root's state.
176
+ - **Owned**: `aria-disabled`, `data-open`, `data-pending`, `data-disabled`, and `onClick` in library mode (and when disabled).
177
+
178
+ No `disabled` prop: the Root carries it. Links and form controls inside the summary keep their own behaviour and do not toggle.
179
+
180
+ ### `Collapsible.Panel`
181
+
182
+ | Prop | Type | Default | Description |
183
+ | - | - | - | - |
184
+ | `transition` | `ViewTransitionClass` | – | Library mode only. Animates content that mounts or changes in the commit that ends an action. |
185
+ | `className` | `string \| ((state: CollapsiblePanelState) => string \| undefined)` | – | A class name, or a function of the part's state. |
186
+ | `style` | `CSSProperties \| ((state: CollapsiblePanelState) => CSSProperties \| undefined)` | – | Inline style, or a function of the part's state. |
187
+ | `children` | `ReactNode \| ((state: CollapsiblePanelState) => ReactNode)` | – | Always mounted. The function form receives committed open: use it to mount content lazily (library mode). |
188
+ | `render` | `ReactElement \| ((props, state: CollapsiblePanelState) => ReactNode)` | – | Replace the default \<div> (element form) or take over rendering (function form). |
189
+
190
+ - **State**: `CollapsiblePanelState` is `{ open, disabled }`; `open` is committed (`undefined` in JS-free mode).
191
+ - **Owned**: `data-disabled`.
192
+
193
+ No `keepMounted`: closed content is always in the DOM, which keeps it searchable. No `data-open` either: select `details:open > .panel`.
194
+
195
+ ## Data attributes
196
+
197
+ | Hook | On | Meaning |
198
+ | - | - | - |
199
+ | `:open` | Root (`details`) | Committed open state, both modes. |
200
+ | `data-open` | Root, Trigger | Optimistic open state (library mode only). |
201
+ | `data-pending` | Root, Trigger | An action is in flight (library mode only). |
202
+ | `data-disabled` | Root, Trigger, Panel | The Root's `disabled` prop. |
203
+ | `aria-disabled` | Trigger | `"true"` when disabled. |
204
+ | `::details-content` | Root | The native content slot: animate it. |
205
+
206
+ ```css
207
+ .c > summary { list-style: none; } /* hide the UA marker */
208
+ .c > summary::-webkit-details-marker { display: none; }
209
+ .c > summary::before { content: "▸"; }
210
+ .c:open > summary:not([data-pending])::before,
211
+ .c > summary[data-open]::before { content: "▾"; } /* flips at once in library mode */
212
+
213
+ /* Open/close animation, every engine, both modes */
214
+ .c::details-content {
215
+ display: grid;
216
+ grid-template-rows: 0fr;
217
+ transition: grid-template-rows 200ms ease, content-visibility 200ms allow-discrete;
218
+ }
219
+ .c:open::details-content { grid-template-rows: 1fr; }
220
+ .c > .panel { min-height: 0; overflow: hidden; }
221
+
222
+ @media (prefers-reduced-motion: reduce) {
223
+ .c::details-content { transition: none; }
224
+ }
225
+ ```
226
+
227
+ ## Keyboard and ARIA
228
+
229
+ | Key | Behaviour |
230
+ | - | - |
231
+ | Enter / Space on the trigger | Toggles (native). |
232
+ | Tab / Shift+Tab | The trigger is a tab stop; closed content is skipped. |
233
+
234
+ - The `<details>` is a group and the summary the engine's disclosure control, with its expanded state from `open`. No `aria-*` is added except `aria-disabled`.
235
+ - HTML forbids `aria-expanded` on a summary, so assistive technology hears the committed state; `data-open` is visual only. For an audible pending state, render an `aria-live` region from the Trigger's state.
236
+ - The accessible name is the Trigger's content; a label that changes ("Show replies" / "Hide replies") is announced through the name, on top of the expanded state.
237
+ - A disabled trigger stays focusable. Focus never moves on open or close.
238
+
239
+ ## Transition types
240
+
241
+ Concept: [Transitions & ViewTransition](../concepts/transitions.md#transition-types)
242
+
243
+ Library mode: `fsui-collapsible` plus `fsui-collapsible-expand` or `fsui-collapsible-collapse`. JS-free mode starts no transitions.
244
+
245
+ ## Optimistic and pending
246
+
247
+ Concept: [Pending & optimistic state](../concepts/pending-and-optimistic.md)
248
+
249
+ Library mode: the Root and Trigger show the optimistic open state (`data-open`) and `data-pending` while an action is in flight. The `<details>` element (`:open`, and what assistive technology hears) and the Panel's function child follow the committed state. A second click while pending reverses the first; `data-pending` stays until both actions have settled. JS-free mode has no optimistic or pending state.
250
+
251
+ ### Walkthrough (async action)
252
+
253
+ ```tsx title="CollapsibleFilters.tsx"
254
+ "use client";
255
+ import { startTransition, useState } from "react";
256
+ import { Collapsible } from "@funstack/ui/collapsible";
257
+ import { DemoErrorBoundary } from "./DemoErrorBoundary.js";
258
+ import { fakeSave } from "./fake-api.js";
259
+
260
+ // Library mode with an async action: every toggle saves the preference first (0.8 s) and the
261
+ // panel opens or closes when the save resolves. Meanwhile the chevron already shows the
262
+ // optimistic state (`data-open`) and the trigger is `data-pending`. Tick "fail" to see a
263
+ // rejected save: `data-open` reverts and the error goes to the nearest Error Boundary.
264
+ export function CollapsibleFilters() {
265
+ const [fail, setFail] = useState(false);
266
+ const [saved, setSaved] = useState<boolean | null>(null);
267
+ return (
268
+ <>
269
+ <DemoErrorBoundary>
270
+ <Collapsible.Root
271
+ className="demo-collapsible"
272
+ openChangeAction={async (open) => {
273
+ await fakeSave("the preference", { fail });
274
+ startTransition(() => setSaved(open)); // after an await: re-wrap (React limitation)
275
+ }}
276
+ >
277
+ <Collapsible.Trigger className="demo-collapsible-trigger">Filters</Collapsible.Trigger>
278
+ <Collapsible.Panel className="demo-collapsible-panel">
279
+ <p>Price, brand and rating filters would go here.</p>
280
+ </Collapsible.Panel>
281
+ </Collapsible.Root>
282
+ </DemoErrorBoundary>
283
+ <label className="demo-readout">
284
+ <input type="checkbox" checked={fail} onChange={(e) => setFail(e.target.checked)} /> fail
285
+ the next save
286
+ </label>
287
+ <output className="demo-readout">
288
+ saved: <code>{saved === null ? "nothing yet" : saved ? "open" : "closed"}</code>
289
+ </output>
290
+ </>
291
+ );
292
+ }
293
+ ```
294
+
295
+ `collapsible.css`: the same file as above.
296
+
297
+ 1. Click the trigger: the click is intercepted, the chevron flips (`data-open`), the Root and trigger get `data-pending`, and `openChangeAction(true, { reason: "activate" })` runs.
298
+ 2. The save resolves: the `<details>` opens (committed state) and `data-pending` goes.
299
+ 3. If the action rejects, `data-open` reverts, the content never opens, and the error goes to the nearest Error Boundary.
300
+
301
+ > **Find-in-page in library mode**
302
+ >
303
+ > The browser opens a closed Collapsible when find-in-page or a text fragment matches its content. That is dispatched as `reason: "platform"` with the `toggle` event; the content stays visible while the action runs. If a controlled parent does not adopt the change, it is closed again when the action settles; a rejection goes to the nearest Error Boundary. A disabled Collapsible is re-closed without dispatching.
304
+
305
+ ## Suspense
306
+
307
+ Concept: [Suspense](../concepts/suspense.md)
308
+
309
+ The Panel is always mounted; its function child receives the committed `open`, which is how you mount content lazily (library mode: `defaultOpen={false}` is enough). If that content suspends, the `<details>` stays closed with the trigger pending until the content is ready, then opens. Trigger content must not suspend.
310
+
311
+ ```tsx title="CollapsibleReplies.tsx"
312
+ "use client";
313
+ import { use } from "react";
314
+ import { Collapsible } from "@funstack/ui/collapsible";
315
+ import { sleep } from "./fake-api.js";
316
+
317
+ let replies: Promise<string[]> | undefined;
318
+ function loadReplies(): Promise<string[]> {
319
+ replies ??= sleep(1200).then(() => ["Looks good to me.", "Ship it!", "One nit, see inline."]);
320
+ return replies;
321
+ }
322
+
323
+ function ReplyList() {
324
+ return (
325
+ <ul>
326
+ {use(loadReplies()).map((reply) => (
327
+ <li key={reply}>{reply}</li>
328
+ ))}
329
+ </ul>
330
+ );
331
+ }
332
+
333
+ // Library mode without an action: `defaultOpen={false}` alone selects it. The Panel's function
334
+ // child mounts <ReplyList> only once the Collapsible is open in committed state. The replies
335
+ // suspend for 1.2 s; because opening is a transition, the <details> stays closed with a spinner
336
+ // on the trigger until the data is ready, then opens with its content. No Suspense fallback.
337
+ export function CollapsibleReplies() {
338
+ return (
339
+ <Collapsible.Root defaultOpen={false} className="demo-collapsible">
340
+ <Collapsible.Trigger className="demo-collapsible-trigger">
341
+ {({ open, pending }) => (
342
+ <>
343
+ {open ? "Hide replies" : "Show 3 replies"}
344
+ {pending && <span className="demo-spinner" aria-hidden />}
345
+ </>
346
+ )}
347
+ </Collapsible.Trigger>
348
+ <Collapsible.Panel className="demo-collapsible-panel">
349
+ {({ open }) => open && <ReplyList />}
350
+ </Collapsible.Panel>
351
+ </Collapsible.Root>
352
+ );
353
+ }
354
+ ```
355
+
356
+ `collapsible.css`: the same file as above.
357
+
358
+ ## Browser-owned state
359
+
360
+ Concept: [Browser-owned state](../concepts/browser-owned-state.md)
361
+
362
+ JS-free mode: the browser owns `<details open>`; style with `:open` and animate with `::details-content`. Library mode: open state is library-owned, but the browser can still open or close the `<details>` (find-in-page, a text fragment, a click before hydration). That is dispatched with `reason: "platform"`, and the committed state is re-applied once the action settles.
363
+
364
+ ## Before hydration
365
+
366
+ Concept: [Server Components](../concepts/server-components.md#before-hydration)
367
+
368
+ JS-free mode: everything: open and close, Enter and Space, find-in-page, CSS animation. Hydration only adds `disabled`. Library mode: the native toggle; a Collapsible toggled before hydration is reconciled on mount with one `openChangeAction` call (`reason: "platform"`, no event).
369
+
370
+ ## Recipes
371
+
372
+ ### Remember the open state with a Server Function
373
+
374
+ ```tsx
375
+ // Server Component
376
+ import { rememberOpen } from "./actions"; // "use server"
377
+
378
+ <Collapsible.Root defaultOpen={prefs.filtersOpen} openChangeAction={rememberOpen.bind(null, "filters")}>
379
+ <Collapsible.Trigger>Filters</Collapsible.Trigger>
380
+ <Collapsible.Panel><Filters /></Collapsible.Panel>
381
+ </Collapsible.Root>
382
+ ```
383
+
384
+ Every toggle waits for the round trip. For a toggle that should not wait, pass a client function that calls the Server Function without returning its promise.
385
+
386
+ ### Open from a control elsewhere
387
+
388
+ ```tsx
389
+ "use client";
390
+ const [open, setOpen] = useState(false);
391
+
392
+ <Button action={() => setOpen(true)}>Show details</Button>
393
+
394
+ <Collapsible.Root open={open} openChangeAction={setOpen}>
395
+ <Collapsible.Trigger>Details</Collapsible.Trigger>
396
+ <Collapsible.Panel>...</Collapsible.Panel>
397
+ </Collapsible.Root>
398
+ ```
399
+
400
+ One setter serves both: the Trigger's click and a find-in-page reveal arrive through `openChangeAction`. The outside control is your own button; give it `aria-expanded` and `aria-controls` if it needs them.
401
+
402
+ ### Animate the box with ViewTransition
403
+
404
+ ```tsx
405
+ <Collapsible.Root defaultOpen={false} transition="grow">...</Collapsible.Root>
406
+ ```
407
+
408
+ Use either the `transition` prop or a `::details-content` CSS transition for a given change, not both. Content after the Collapsible jumps unless you give it a `<ViewTransition>` of its own.