@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,198 @@
1
+ "use client";
2
+ import { dataAttr } from "../internal/data-attr.mjs";
3
+ import { useDevWarning } from "../internal/use-dev-warning.mjs";
4
+ import { disabledButton, rendersButton } from "../internal/render-element.mjs";
5
+ import { useRender } from "../internal/use-render.mjs";
6
+ import { useMergedRefs } from "../internal/use-merged-refs.mjs";
7
+ import { BUTTON_NAME, useNameWarning } from "../internal/use-name-warning.mjs";
8
+ import { ComboboxChipContext, useComboboxContext } from "./combobox-context.mjs";
9
+ import { use, useCallback, useLayoutEffect, useRef } from "react";
10
+ import { jsx } from "react/jsx-runtime";
11
+ //#region src/combobox/combobox-chips.tsx
12
+ const isDev = process.env.NODE_ENV !== "production";
13
+ const NO_VALUES = [];
14
+ const preventDefault = (event) => event.preventDefault();
15
+ /**
16
+ * The selected values of `Combobox.Root multiple` as a list: `<div role="list"
17
+ * aria-labelledby={label}>` (no role while empty: an empty list lacks its required children).
18
+ * It holds the chips, not the Input: the box around both is yours. A press in it keeps focus
19
+ * where it is and its click focuses the Input; a focused chip takes the keys of design 15.6
20
+ * (arrows, Home / End, Backspace / Delete, Escape; a printable key types into the Input).
21
+ *
22
+ * Owned keys (conventions 1.2): `role`, `aria-labelledby` (token-merged, while not empty),
23
+ * `onKeyDown`, `onPointerDown`, `onMouseDown`, `onClick`, `onFocus`, `onBlur`, `data-empty`,
24
+ * `data-pending`, `data-disabled`.
25
+ *
26
+ * @see https://ui.funstack.work/components/combobox
27
+ */
28
+ function ComboboxChips({ className, style, children, render, ...rest }) {
29
+ const ctx = useComboboxContext("Combobox.Chips");
30
+ useDevWarning(!ctx.multiple, isDev && "Combobox.Chips: rendered under a Combobox.Root without `multiple`. Chips show a multiple selection; add `multiple` to the Root.");
31
+ const { chips } = ctx;
32
+ const { chipsRef } = chips;
33
+ const ref = useCallback((element) => {
34
+ chipsRef.current = element;
35
+ return () => {
36
+ if (chipsRef.current === element) chipsRef.current = null;
37
+ };
38
+ }, [chipsRef]);
39
+ const values = ctx.multiple ? ctx.values : NO_VALUES;
40
+ const empty = values.length === 0;
41
+ const state = {
42
+ value: values,
43
+ pending: ctx.multiple && ctx.valuePending,
44
+ disabled: ctx.disabled
45
+ };
46
+ const libraryProps = {
47
+ role: empty ? void 0 : "list",
48
+ ...empty ? {
49
+ "aria-label": void 0,
50
+ "aria-labelledby": void 0
51
+ } : ctx.hasLabel ? { "aria-labelledby": ctx.ids.label } : ctx.fieldLabelId !== void 0 && { "aria-labelledby": ctx.fieldLabelId },
52
+ onKeyDown: (event) => chips.keyDown(event.nativeEvent),
53
+ onPointerDown: (event) => preventDefault(event),
54
+ onMouseDown: (event) => preventDefault(event),
55
+ onClick: (event) => chips.click(event.nativeEvent),
56
+ onFocus: (event) => chips.focusIn(event.nativeEvent),
57
+ onBlur: (event) => chips.focusOut(event.nativeEvent),
58
+ "data-empty": dataAttr(empty),
59
+ "data-pending": dataAttr(state.pending),
60
+ "data-disabled": dataAttr(ctx.disabled)
61
+ };
62
+ return useRender({
63
+ defaultElement: "div",
64
+ render,
65
+ state,
66
+ className,
67
+ style,
68
+ children,
69
+ props: rest,
70
+ libraryProps,
71
+ ref
72
+ });
73
+ }
74
+ ComboboxChips.displayName = "ComboboxChips";
75
+ /**
76
+ * One selected value: `<div role="listitem" tabindex="-1">`, focusable by the keys of design 15.6
77
+ * and never a Tab stop (the combobox has one, the Input). Renders from the optimistic value, so a
78
+ * removed chip disappears at once and comes back if its action rejects; `data-pending` while its
79
+ * addition is not committed.
80
+ *
81
+ * Owned keys (conventions 1.2): `role`, `tabIndex`, `data-pending`, `data-disabled`.
82
+ *
83
+ * @see https://ui.funstack.work/components/combobox
84
+ */
85
+ function ComboboxChip({ value, label, className, style, children, render, ...rest }) {
86
+ const ctx = useComboboxContext("Combobox.Chip");
87
+ useDevWarning(!ctx.multiple, isDev && "Combobox.Chip: rendered under a Combobox.Root without `multiple`. Chips show a multiple selection; add `multiple` to the Root.");
88
+ useDevWarning(ctx.multiple && !ctx.isSelected(value), isDev && `Combobox.Chip: its value ${JSON.stringify(value)} is not in the selection. Render the chips from the \`value\` that \`Combobox.Chips\` passes to its children.`);
89
+ const { registerChip } = ctx.chips;
90
+ const elementRef = useRef(null);
91
+ const ref = useCallback((element) => {
92
+ elementRef.current = element;
93
+ return () => {
94
+ if (elementRef.current === element) elementRef.current = null;
95
+ };
96
+ }, []);
97
+ useLayoutEffect(() => {
98
+ const element = elementRef.current;
99
+ if (element === null) return;
100
+ return registerChip(value, {
101
+ element,
102
+ label
103
+ });
104
+ }, [
105
+ registerChip,
106
+ value,
107
+ label
108
+ ]);
109
+ const state = {
110
+ value,
111
+ label: ctx.chips.labelOf(value),
112
+ pending: ctx.multiple && ctx.isPending(value),
113
+ disabled: ctx.disabled
114
+ };
115
+ const libraryProps = {
116
+ role: "listitem",
117
+ tabIndex: -1,
118
+ "data-pending": dataAttr(state.pending),
119
+ "data-disabled": dataAttr(ctx.disabled)
120
+ };
121
+ const element = useRender({
122
+ defaultElement: "div",
123
+ render,
124
+ state,
125
+ className,
126
+ style,
127
+ children: children ?? ((s) => s.label ?? s.value),
128
+ props: rest,
129
+ libraryProps,
130
+ ref
131
+ });
132
+ return /* @__PURE__ */ jsx(ComboboxChipContext, {
133
+ value,
134
+ children: element
135
+ });
136
+ }
137
+ ComboboxChip.displayName = "ComboboxChip";
138
+ /**
139
+ * The optional remove button of a chip: `<button type="button" tabindex="-1">`, inside a
140
+ * `Combobox.Chip`. A press keeps focus in the Input (as `Clear`); the click removes the chip's
141
+ * value, announces it and focuses the Input. While the listbox is open the press closes it (the
142
+ * platform's light dismiss: the button is outside the popup). Needs an accessible name
143
+ * (`aria-label`).
144
+ *
145
+ * Owned keys (conventions 1.2): `type` (on a `<button>`), `tabIndex`, `disabled`,
146
+ * `aria-disabled` (link or component `render`), `onClick`, `onPointerDown`, `onMouseDown`,
147
+ * `data-pending`, `data-disabled`.
148
+ *
149
+ * @see https://ui.funstack.work/components/combobox
150
+ */
151
+ function ComboboxChipRemove({ className, style, children, render, ...rest }) {
152
+ const ctx = useComboboxContext("Combobox.ChipRemove");
153
+ const value = use(ComboboxChipContext);
154
+ if (value === null) throw new Error("Combobox.ChipRemove must be rendered inside a Combobox.Chip.");
155
+ useDevWarning(!ctx.multiple, isDev && "Combobox.ChipRemove: rendered under a Combobox.Root without `multiple`. Chips show a multiple selection; add `multiple` to the Root.");
156
+ const nameWarning = useNameWarning(isDev && "Combobox.ChipRemove: the button has no accessible name. Give it an `aria-label`.", BUTTON_NAME);
157
+ const { registerRemove } = ctx.chips;
158
+ const registerRef = useCallback((element) => registerRemove(element), [registerRemove]);
159
+ const ref = useMergedRefs(registerRef, nameWarning);
160
+ const disabled = ctx.disabled;
161
+ const state = {
162
+ value,
163
+ pending: ctx.multiple && ctx.isPending(value),
164
+ disabled
165
+ };
166
+ const libraryProps = {
167
+ ...rendersButton(render) && { type: "button" },
168
+ tabIndex: -1,
169
+ ...disabledButton(render, disabled).props,
170
+ onPointerDown: (event) => preventDefault(event),
171
+ onMouseDown: (event) => preventDefault(event),
172
+ onClick: (event) => {
173
+ if (disabled) {
174
+ event.preventDefault();
175
+ return;
176
+ }
177
+ ctx.chips.removeChip(value, event.nativeEvent);
178
+ },
179
+ "data-pending": dataAttr(state.pending),
180
+ "data-disabled": dataAttr(disabled)
181
+ };
182
+ return useRender({
183
+ defaultElement: "button",
184
+ render,
185
+ state,
186
+ className,
187
+ style,
188
+ children,
189
+ props: rest,
190
+ libraryProps,
191
+ ref
192
+ });
193
+ }
194
+ ComboboxChipRemove.displayName = "ComboboxChipRemove";
195
+ //#endregion
196
+ export { ComboboxChip, ComboboxChipRemove, ComboboxChips };
197
+
198
+ //# sourceMappingURL=combobox-chips.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"combobox-chips.mjs","names":[],"sources":["../../src/combobox/combobox-chips.tsx"],"sourcesContent":["\"use client\";\nimport { use, useCallback, useLayoutEffect, useRef } from \"react\";\nimport type {\n ComponentPropsWithRef,\n CSSProperties,\n FocusEvent,\n KeyboardEvent,\n MouseEvent,\n PointerEvent,\n ReactNode,\n} from \"react\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useDevWarning } from \"../internal/use-dev-warning.js\";\nimport { useMergedRefs } from \"../internal/use-merged-refs.js\";\nimport { BUTTON_NAME, useNameWarning } from \"../internal/use-name-warning.js\";\nimport { disabledButton, rendersButton, useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport { ComboboxChipContext, useComboboxContext } from \"./combobox-context.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\nconst NO_VALUES: readonly string[] = [];\n\nconst preventDefault = (event: { preventDefault(): void }) => event.preventDefault();\n\n/**\n * State of `Combobox.Chips`, passed to the function forms of `className`, `style`, `children` and\n * `render`.\n */\nexport interface ComboboxChipsState {\n /** Optimistic selection, in pick order: render one `Chip` per value. */\n readonly value: readonly string[];\n /** The Root's value action is in flight. */\n readonly pending: boolean;\n /** The Root's `disabled` (or the Field's). */\n readonly disabled: boolean;\n}\n\n/**\n * Props of `Combobox.Chips`.\n *\n * @see https://ui.funstack.work/components/combobox\n */\nexport interface ComboboxChipsProps extends Omit<\n ComponentPropsWithRef<\"div\">,\n | \"role\"\n | \"onKeyDown\"\n | \"onPointerDown\"\n | \"onMouseDown\"\n | \"onClick\"\n | \"onFocus\"\n | \"onBlur\"\n | \"className\"\n | \"style\"\n | \"children\"\n> {\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, ComboboxChipsState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, ComboboxChipsState>;\n /**\n * Usually a function of `{ value }` rendering one `Chip` per value, keyed by the value.\n * Rendered from optimistic state; must not suspend.\n */\n children?: StateValue<ReactNode, ComboboxChipsState>;\n /** Replace the default `<div>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"div\">, ComboboxChipsState>;\n}\n\n/**\n * The selected values of `Combobox.Root multiple` as a list: `<div role=\"list\"\n * aria-labelledby={label}>` (no role while empty: an empty list lacks its required children).\n * It holds the chips, not the Input: the box around both is yours. A press in it keeps focus\n * where it is and its click focuses the Input; a focused chip takes the keys of design 15.6\n * (arrows, Home / End, Backspace / Delete, Escape; a printable key types into the Input).\n *\n * Owned keys (conventions 1.2): `role`, `aria-labelledby` (token-merged, while not empty),\n * `onKeyDown`, `onPointerDown`, `onMouseDown`, `onClick`, `onFocus`, `onBlur`, `data-empty`,\n * `data-pending`, `data-disabled`.\n *\n * @see https://ui.funstack.work/components/combobox\n */\nexport function ComboboxChips({ className, style, children, render, ...rest }: ComboboxChipsProps) {\n const ctx = useComboboxContext(\"Combobox.Chips\");\n useDevWarning(\n !ctx.multiple,\n isDev &&\n \"Combobox.Chips: rendered under a Combobox.Root without `multiple`. Chips show a multiple selection; \" +\n \"add `multiple` to the Root.\",\n );\n const { chips } = ctx;\n const { chipsRef } = chips;\n\n const ref = useCallback(\n (element: HTMLElement) => {\n chipsRef.current = element;\n return () => {\n if (chipsRef.current === element) chipsRef.current = null;\n };\n },\n [chipsRef],\n );\n\n const values = ctx.multiple ? ctx.values : NO_VALUES;\n const empty = values.length === 0;\n const state: ComboboxChipsState = {\n value: values,\n pending: ctx.multiple && ctx.valuePending,\n disabled: ctx.disabled,\n };\n\n const libraryProps: ComponentPropsWithRef<\"div\"> & DataAttributes = {\n role: empty ? undefined : \"list\",\n // Named like the List: by the Label while one is mounted, else the Field's label. While\n // empty there is no role, and a role-less `div` may not be named: the consumer's\n // `aria-label` / `aria-labelledby` are removed too (owned keys set to `undefined`).\n ...(empty\n ? { \"aria-label\": undefined, \"aria-labelledby\": undefined }\n : ctx.hasLabel\n ? { \"aria-labelledby\": ctx.ids.label }\n : ctx.fieldLabelId !== undefined && { \"aria-labelledby\": ctx.fieldLabelId }),\n onKeyDown: (event: KeyboardEvent<HTMLDivElement>) => chips.keyDown(event.nativeEvent),\n // The Input keeps focus (a chip is focused by keys only, design 15.6).\n onPointerDown: (event: PointerEvent<HTMLDivElement>) => preventDefault(event),\n onMouseDown: (event: MouseEvent<HTMLDivElement>) => preventDefault(event),\n onClick: (event: MouseEvent<HTMLDivElement>) => chips.click(event.nativeEvent),\n onFocus: (event: FocusEvent<HTMLDivElement>) => chips.focusIn(event.nativeEvent),\n onBlur: (event: FocusEvent<HTMLDivElement>) => chips.focusOut(event.nativeEvent),\n \"data-empty\": dataAttr(empty),\n \"data-pending\": dataAttr(state.pending),\n \"data-disabled\": dataAttr(ctx.disabled),\n };\n\n return useRender<ComponentPropsWithRef<\"div\">, ComboboxChipsState>({\n defaultElement: \"div\",\n render,\n state,\n className,\n style,\n children,\n props: rest,\n libraryProps,\n ref,\n });\n}\n\nComboboxChips.displayName = \"ComboboxChips\";\n\n/**\n * State of `Combobox.Chip`, passed to the function forms of `className`, `style`, `children` and\n * `render`.\n */\nexport interface ComboboxChipState {\n /** The Chip's `value` prop. */\n readonly value: string;\n /**\n * The text of the option with this value as the library last saw it (written at the pick);\n * `undefined` if no Option for it was ever mounted (a preselected value before the listbox\n * first opens).\n */\n readonly label: string | undefined;\n /** The Root's value action is pending and this value is not in the committed selection yet. */\n readonly pending: boolean;\n /** The Root's `disabled` (or the Field's). */\n readonly disabled: boolean;\n}\n\n/**\n * Props of `Combobox.Chip`.\n *\n * @see https://ui.funstack.work/components/combobox\n */\nexport interface ComboboxChipProps extends Omit<\n ComponentPropsWithRef<\"div\">,\n \"role\" | \"tabIndex\" | \"className\" | \"style\" | \"children\"\n> {\n /** The selected value this chip shows. */\n value: string;\n /**\n * The chip's text for the removal announcement.\n *\n * @defaultValue `state.label`, else the element's trimmed `textContent`\n */\n label?: string;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, ComboboxChipState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, ComboboxChipState>;\n /**\n * Content, or a function of the part's state. Rendered from optimistic state; must not\n * suspend.\n *\n * @defaultValue `label ?? value` (the state's `label`)\n */\n children?: StateValue<ReactNode, ComboboxChipState>;\n /** Replace the default `<div>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"div\">, ComboboxChipState>;\n}\n\n/**\n * One selected value: `<div role=\"listitem\" tabindex=\"-1\">`, focusable by the keys of design 15.6\n * and never a Tab stop (the combobox has one, the Input). Renders from the optimistic value, so a\n * removed chip disappears at once and comes back if its action rejects; `data-pending` while its\n * addition is not committed.\n *\n * Owned keys (conventions 1.2): `role`, `tabIndex`, `data-pending`, `data-disabled`.\n *\n * @see https://ui.funstack.work/components/combobox\n */\nexport function ComboboxChip({\n value,\n label,\n className,\n style,\n children,\n render,\n ...rest\n}: ComboboxChipProps) {\n const ctx = useComboboxContext(\"Combobox.Chip\");\n useDevWarning(\n !ctx.multiple,\n isDev &&\n \"Combobox.Chip: rendered under a Combobox.Root without `multiple`. Chips show a multiple selection; \" +\n \"add `multiple` to the Root.\",\n );\n useDevWarning(\n ctx.multiple && !ctx.isSelected(value),\n isDev &&\n `Combobox.Chip: its value ${JSON.stringify(value)} is not in the selection. Render the ` +\n \"chips from the `value` that `Combobox.Chips` passes to its children.\",\n );\n const { registerChip } = ctx.chips;\n\n const elementRef = useRef<HTMLElement | null>(null);\n const ref = useCallback((element: HTMLElement) => {\n elementRef.current = element;\n return () => {\n if (elementRef.current === element) elementRef.current = null;\n };\n }, []);\n useLayoutEffect(() => {\n const element = elementRef.current;\n if (element === null) return;\n return registerChip(value, { element, label });\n }, [registerChip, value, label]);\n\n const state: ComboboxChipState = {\n value,\n label: ctx.chips.labelOf(value),\n pending: ctx.multiple && ctx.isPending(value),\n disabled: ctx.disabled,\n };\n\n const libraryProps: ComponentPropsWithRef<\"div\"> & DataAttributes = {\n role: \"listitem\",\n tabIndex: -1,\n \"data-pending\": dataAttr(state.pending),\n \"data-disabled\": dataAttr(ctx.disabled),\n };\n\n const element = useRender<ComponentPropsWithRef<\"div\">, ComboboxChipState>({\n defaultElement: \"div\",\n render,\n state,\n className,\n style,\n children: children ?? ((s) => s.label ?? s.value),\n props: rest,\n libraryProps,\n ref,\n });\n return <ComboboxChipContext value={value}>{element}</ComboboxChipContext>;\n}\n\nComboboxChip.displayName = \"ComboboxChip\";\n\n/**\n * State of `Combobox.ChipRemove`, passed to the function forms of `className`, `style`,\n * `children` and `render`.\n */\nexport interface ComboboxChipRemoveState {\n /** The value of the Chip it is in. */\n readonly value: string;\n /** As the Chip's `pending`. */\n readonly pending: boolean;\n /** The Root's `disabled` (or the Field's). */\n readonly disabled: boolean;\n}\n\n/**\n * Props of `Combobox.ChipRemove`.\n *\n * @see https://ui.funstack.work/components/combobox\n */\nexport interface ComboboxChipRemoveProps extends Omit<\n ComponentPropsWithRef<\"button\">,\n | \"onClick\"\n | \"onPointerDown\"\n | \"onMouseDown\"\n | \"tabIndex\"\n | \"disabled\"\n | \"className\"\n | \"style\"\n | \"children\"\n> {\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, ComboboxChipRemoveState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, ComboboxChipRemoveState>;\n /**\n * Content, or a function of the part's state, usually an icon (\"×\", best in an `aria-hidden`\n * element). It is never part of the chip's text in the removal announcement.\n */\n children?: StateValue<ReactNode, ComboboxChipRemoveState>;\n /** Should render a `<button>`. */\n render?: RenderProp<ComponentPropsWithRef<\"button\">, ComboboxChipRemoveState>;\n}\n\n/**\n * The optional remove button of a chip: `<button type=\"button\" tabindex=\"-1\">`, inside a\n * `Combobox.Chip`. A press keeps focus in the Input (as `Clear`); the click removes the chip's\n * value, announces it and focuses the Input. While the listbox is open the press closes it (the\n * platform's light dismiss: the button is outside the popup). Needs an accessible name\n * (`aria-label`).\n *\n * Owned keys (conventions 1.2): `type` (on a `<button>`), `tabIndex`, `disabled`,\n * `aria-disabled` (link or component `render`), `onClick`, `onPointerDown`, `onMouseDown`,\n * `data-pending`, `data-disabled`.\n *\n * @see https://ui.funstack.work/components/combobox\n */\nexport function ComboboxChipRemove({\n className,\n style,\n children,\n render,\n ...rest\n}: ComboboxChipRemoveProps) {\n const ctx = useComboboxContext(\"Combobox.ChipRemove\");\n const value = use(ComboboxChipContext);\n if (value === null) {\n throw new Error(\"Combobox.ChipRemove must be rendered inside a Combobox.Chip.\");\n }\n useDevWarning(\n !ctx.multiple,\n isDev &&\n \"Combobox.ChipRemove: rendered under a Combobox.Root without `multiple`. Chips show a multiple selection; \" +\n \"add `multiple` to the Root.\",\n );\n const nameWarning = useNameWarning(\n isDev && \"Combobox.ChipRemove: the button has no accessible name. Give it an `aria-label`.\",\n BUTTON_NAME,\n );\n const { registerRemove } = ctx.chips;\n // Registered so that its content (a \"×\") is not read as part of the chip's label (15.7).\n const registerRef = useCallback(\n (element: HTMLElement) => registerRemove(element),\n [registerRemove],\n );\n const ref = useMergedRefs<HTMLElement>(registerRef, nameWarning);\n const disabled = ctx.disabled;\n const state: ComboboxChipRemoveState = {\n value,\n pending: ctx.multiple && ctx.isPending(value),\n disabled,\n };\n\n const libraryProps: ComponentPropsWithRef<\"button\"> & DataAttributes = {\n ...(rendersButton(render) && { type: \"button\" as const }),\n tabIndex: -1,\n ...disabledButton(render, disabled).props,\n onPointerDown: (event: PointerEvent<HTMLButtonElement>) => preventDefault(event),\n onMouseDown: (event: MouseEvent<HTMLButtonElement>) => preventDefault(event),\n onClick: (event: MouseEvent<HTMLButtonElement>) => {\n if (disabled) {\n // A disabled link must not navigate either.\n event.preventDefault();\n return;\n }\n ctx.chips.removeChip(value, event.nativeEvent);\n },\n \"data-pending\": dataAttr(state.pending),\n \"data-disabled\": dataAttr(disabled),\n };\n\n return useRender<ComponentPropsWithRef<\"button\">, ComboboxChipRemoveState>({\n defaultElement: \"button\",\n render,\n state,\n className,\n style,\n children,\n props: rest,\n libraryProps,\n ref,\n });\n}\n\nComboboxChipRemove.displayName = \"ComboboxChipRemove\";\n"],"mappings":";;;;;;;;;;;AAoBA,MAAM,QAAQ,QAAQ,IAAI,aAAa;AAEvC,MAAM,YAA+B,CAAC;AAEtC,MAAM,kBAAkB,UAAsC,MAAM,eAAe;;;;;;;;;;;;;;AA2DnF,SAAgB,cAAc,EAAE,WAAW,OAAO,UAAU,QAAQ,GAAG,QAA4B;CACjG,MAAM,MAAM,mBAAmB,gBAAgB;CAC/C,cACE,CAAC,IAAI,UACL,SACE,iIAEJ;CACA,MAAM,EAAE,UAAU;CAClB,MAAM,EAAE,aAAa;CAErB,MAAM,MAAM,aACT,YAAyB;EACxB,SAAS,UAAU;EACnB,aAAa;GACX,IAAI,SAAS,YAAY,SAAS,SAAS,UAAU;EACvD;CACF,GACA,CAAC,QAAQ,CACX;CAEA,MAAM,SAAS,IAAI,WAAW,IAAI,SAAS;CAC3C,MAAM,QAAQ,OAAO,WAAW;CAChC,MAAM,QAA4B;EAChC,OAAO;EACP,SAAS,IAAI,YAAY,IAAI;EAC7B,UAAU,IAAI;CAChB;CAEA,MAAM,eAA8D;EAClE,MAAM,QAAQ,KAAA,IAAY;EAI1B,GAAI,QACA;GAAE,cAAc,KAAA;GAAW,mBAAmB,KAAA;EAAU,IACxD,IAAI,WACF,EAAE,mBAAmB,IAAI,IAAI,MAAM,IACnC,IAAI,iBAAiB,KAAA,KAAa,EAAE,mBAAmB,IAAI,aAAa;EAC9E,YAAY,UAAyC,MAAM,QAAQ,MAAM,WAAW;EAEpF,gBAAgB,UAAwC,eAAe,KAAK;EAC5E,cAAc,UAAsC,eAAe,KAAK;EACxE,UAAU,UAAsC,MAAM,MAAM,MAAM,WAAW;EAC7E,UAAU,UAAsC,MAAM,QAAQ,MAAM,WAAW;EAC/E,SAAS,UAAsC,MAAM,SAAS,MAAM,WAAW;EAC/E,cAAc,SAAS,KAAK;EAC5B,gBAAgB,SAAS,MAAM,OAAO;EACtC,iBAAiB,SAAS,IAAI,QAAQ;CACxC;CAEA,OAAO,UAA4D;EACjE,gBAAgB;EAChB;EACA;EACA;EACA;EACA;EACA,OAAO;EACP;EACA;CACF,CAAC;AACH;AAEA,cAAc,cAAc;;;;;;;;;;;AA+D5B,SAAgB,aAAa,EAC3B,OACA,OACA,WACA,OACA,UACA,QACA,GAAG,QACiB;CACpB,MAAM,MAAM,mBAAmB,eAAe;CAC9C,cACE,CAAC,IAAI,UACL,SACE,gIAEJ;CACA,cACE,IAAI,YAAY,CAAC,IAAI,WAAW,KAAK,GACrC,SACE,4BAA4B,KAAK,UAAU,KAAK,EAAE,8GAEtD;CACA,MAAM,EAAE,iBAAiB,IAAI;CAE7B,MAAM,aAAa,OAA2B,IAAI;CAClD,MAAM,MAAM,aAAa,YAAyB;EAChD,WAAW,UAAU;EACrB,aAAa;GACX,IAAI,WAAW,YAAY,SAAS,WAAW,UAAU;EAC3D;CACF,GAAG,CAAC,CAAC;CACL,sBAAsB;EACpB,MAAM,UAAU,WAAW;EAC3B,IAAI,YAAY,MAAM;EACtB,OAAO,aAAa,OAAO;GAAE;GAAS;EAAM,CAAC;CAC/C,GAAG;EAAC;EAAc;EAAO;CAAK,CAAC;CAE/B,MAAM,QAA2B;EAC/B;EACA,OAAO,IAAI,MAAM,QAAQ,KAAK;EAC9B,SAAS,IAAI,YAAY,IAAI,UAAU,KAAK;EAC5C,UAAU,IAAI;CAChB;CAEA,MAAM,eAA8D;EAClE,MAAM;EACN,UAAU;EACV,gBAAgB,SAAS,MAAM,OAAO;EACtC,iBAAiB,SAAS,IAAI,QAAQ;CACxC;CAEA,MAAM,UAAU,UAA2D;EACzE,gBAAgB;EAChB;EACA;EACA;EACA;EACA,UAAU,cAAc,MAAM,EAAE,SAAS,EAAE;EAC3C,OAAO;EACP;EACA;CACF,CAAC;CACD,OAAO,oBAAC,qBAAD;EAA4B;EAAQ,UAAA;CAA6B,CAAA;AAC1E;AAEA,aAAa,cAAc;;;;;;;;;;;;;;AAyD3B,SAAgB,mBAAmB,EACjC,WACA,OACA,UACA,QACA,GAAG,QACuB;CAC1B,MAAM,MAAM,mBAAmB,qBAAqB;CACpD,MAAM,QAAQ,IAAI,mBAAmB;CACrC,IAAI,UAAU,MACZ,MAAM,IAAI,MAAM,8DAA8D;CAEhF,cACE,CAAC,IAAI,UACL,SACE,sIAEJ;CACA,MAAM,cAAc,eAClB,SAAS,oFACT,WACF;CACA,MAAM,EAAE,mBAAmB,IAAI;CAE/B,MAAM,cAAc,aACjB,YAAyB,eAAe,OAAO,GAChD,CAAC,cAAc,CACjB;CACA,MAAM,MAAM,cAA2B,aAAa,WAAW;CAC/D,MAAM,WAAW,IAAI;CACrB,MAAM,QAAiC;EACrC;EACA,SAAS,IAAI,YAAY,IAAI,UAAU,KAAK;EAC5C;CACF;CAEA,MAAM,eAAiE;EACrE,GAAI,cAAc,MAAM,KAAK,EAAE,MAAM,SAAkB;EACvD,UAAU;EACV,GAAG,eAAe,QAAQ,QAAQ,CAAC,CAAC;EACpC,gBAAgB,UAA2C,eAAe,KAAK;EAC/E,cAAc,UAAyC,eAAe,KAAK;EAC3E,UAAU,UAAyC;GACjD,IAAI,UAAU;IAEZ,MAAM,eAAe;IACrB;GACF;GACA,IAAI,MAAM,WAAW,OAAO,MAAM,WAAW;EAC/C;EACA,gBAAgB,SAAS,MAAM,OAAO;EACtC,iBAAiB,SAAS,QAAQ;CACpC;CAEA,OAAO,UAAoE;EACzE,gBAAgB;EAChB;EACA;EACA;EACA;EACA;EACA,OAAO;EACP;EACA;CACF,CAAC;AACH;AAEA,mBAAmB,cAAc"}
@@ -6,8 +6,10 @@ import { CSSProperties, ComponentPropsWithRef, ReactNode } from "react";
6
6
  * `render`.
7
7
  */
8
8
  export interface ComboboxClearState {
9
- /** Optimistic selection. */
9
+ /** Optimistic selection; always `null` with `multiple` (read `values`). */
10
10
  readonly value: string | null;
11
+ /** Optimistic selection as a list: pick order with `multiple`, `[value]` or `[]` otherwise. */
12
+ readonly values: readonly string[];
11
13
  /** The text in the input (urgent). */
12
14
  readonly inputValue: string;
13
15
  /** Disabled by its own prop or by the Root. */
@@ -37,7 +39,8 @@ export interface ComboboxClearProps extends Omit<ComponentPropsWithRef<"button">
37
39
  }
38
40
  /**
39
41
  * The optional button that clears the combobox: `<button type="button" tabindex="-1">`. A click
40
- * empties the text (urgent) and dispatches `valueChangeAction(null)` unless nothing is selected;
42
+ * empties the text (urgent) and dispatches `valueChangeAction(null)` (with `multiple`: one change
43
+ * that removes every value, announced) unless nothing is selected;
41
44
  * the input keeps focus. Always rendered: hide it with CSS (`:placeholder-shown`) or `state`.
42
45
  * A click while the listbox is open closes it (the platform's light dismiss: the button is
43
46
  * outside the popup).
@@ -1 +1 @@
1
- {"version":3,"file":"combobox-clear.d.mts","names":[],"sources":["../../src/combobox/combobox-clear.tsx"],"mappings":";;;;;;;iBAqBiB;;WAEN;;WAEA;;WAEA;;;;;;;iBAQM,2BAA2B,KAC1C;;;;;;;EAgBA;;EAEA,YAAY,+BAA+B;;EAE3C,QAAQ,WAAW,2BAA2B;;EAE9C,WAAW,WAAW,WAAW;;EAEjC,SAAS,WAAW,iCAAiC;;;;;;;;;;;;;;wBAevC,gBACd,UAAU,aACV,WACA,OACA,UACA,WACG,QACF,qBAAkB;yBAPL"}
1
+ {"version":3,"file":"combobox-clear.d.mts","names":[],"sources":["../../src/combobox/combobox-clear.tsx"],"mappings":";;;;;;;iBAqBiB;;WAEN;;WAEA;;WAEA;;WAEA;;;;;;;iBAQM,2BAA2B,KAC1C;;;;;;;EAgBA;;EAEA,YAAY,+BAA+B;;EAE3C,QAAQ,WAAW,2BAA2B;;EAE9C,WAAW,WAAW,WAAW;;EAEjC,SAAS,WAAW,iCAAiC;;;;;;;;;;;;;;;wBAgBvC,gBACd,UAAU,aACV,WACA,OACA,UACA,WACG,QACF,qBAAkB;yBAPL"}
@@ -8,7 +8,8 @@ import { useComboboxContext } from "./combobox-context.mjs";
8
8
  const isDev = process.env.NODE_ENV !== "production";
9
9
  /**
10
10
  * The optional button that clears the combobox: `<button type="button" tabindex="-1">`. A click
11
- * empties the text (urgent) and dispatches `valueChangeAction(null)` unless nothing is selected;
11
+ * empties the text (urgent) and dispatches `valueChangeAction(null)` (with `multiple`: one change
12
+ * that removes every value, announced) unless nothing is selected;
12
13
  * the input keeps focus. Always rendered: hide it with CSS (`:placeholder-shown`) or `state`.
13
14
  * A click while the listbox is open closes it (the platform's light dismiss: the button is
14
15
  * outside the popup).
@@ -24,6 +25,7 @@ function ComboboxClear({ disabled: ownDisabled = false, className, style, childr
24
25
  const ref = useNameWarning(isDev && "Combobox.Clear: the button has no accessible name. Give it an `aria-label`.", BUTTON_NAME);
25
26
  const state = {
26
27
  value: ctx.value,
28
+ values: ctx.values,
27
29
  inputValue: ctx.inputValue,
28
30
  disabled
29
31
  };
@@ -1 +1 @@
1
- {"version":3,"file":"combobox-clear.mjs","names":[],"sources":["../../src/combobox/combobox-clear.tsx"],"sourcesContent":["\"use client\";\nimport type {\n ComponentPropsWithRef,\n CSSProperties,\n MouseEvent,\n PointerEvent,\n ReactNode,\n} from \"react\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { BUTTON_NAME, useNameWarning } from \"../internal/use-name-warning.js\";\nimport { disabledButton, rendersButton, useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport { useComboboxContext } from \"./combobox-context.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/**\n * State of `Combobox.Clear`, passed to the function forms of `className`, `style`, `children` and\n * `render`.\n */\nexport interface ComboboxClearState {\n /** Optimistic selection. */\n readonly value: string | null;\n /** The text in the input (urgent). */\n readonly inputValue: string;\n /** Disabled by its own prop or by the Root. */\n readonly disabled: boolean;\n}\n\n/**\n * Props of `Combobox.Clear`.\n *\n * @see https://ui.funstack.work/components/combobox\n */\nexport interface ComboboxClearProps extends Omit<\n ComponentPropsWithRef<\"button\">,\n | \"onClick\"\n | \"onPointerDown\"\n | \"onMouseDown\"\n | \"tabIndex\"\n | \"disabled\"\n | \"className\"\n | \"style\"\n | \"children\"\n> {\n /**\n * Disables this button; the Root's `disabled` does too. Native `disabled` on a `<button>`; with\n * a link or component `render`, `aria-disabled=\"true\"` instead.\n *\n * @defaultValue `false`\n */\n disabled?: boolean;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, ComboboxClearState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, ComboboxClearState>;\n /** Content, or a function of the part's state. */\n children?: StateValue<ReactNode, ComboboxClearState>;\n /** Should render a `<button>`. */\n render?: RenderProp<ComponentPropsWithRef<\"button\">, ComboboxClearState>;\n}\n\n/**\n * The optional button that clears the combobox: `<button type=\"button\" tabindex=\"-1\">`. A click\n * empties the text (urgent) and dispatches `valueChangeAction(null)` unless nothing is selected;\n * the input keeps focus. Always rendered: hide it with CSS (`:placeholder-shown`) or `state`.\n * A click while the listbox is open closes it (the platform's light dismiss: the button is\n * outside the popup).\n *\n * Owned keys: `type` (on a `<button>`), `tabIndex`, `disabled`, `aria-disabled` (link or component\n * `render`), `onClick`, `onPointerDown`, `onMouseDown`, `data-disabled`.\n *\n * @see https://ui.funstack.work/components/combobox\n */\nexport function ComboboxClear({\n disabled: ownDisabled = false,\n className,\n style,\n children,\n render,\n ...rest\n}: ComboboxClearProps) {\n const ctx = useComboboxContext(\"Combobox.Clear\");\n const disabled = ownDisabled || ctx.disabled;\n const ref = useNameWarning(\n isDev && \"Combobox.Clear: the button has no accessible name. Give it an `aria-label`.\",\n BUTTON_NAME,\n );\n const state: ComboboxClearState = { value: ctx.value, inputValue: ctx.inputValue, disabled };\n\n const libraryProps: ComponentPropsWithRef<\"button\"> & DataAttributes = {\n ...(rendersButton(render) && { type: \"button\" as const }),\n tabIndex: -1,\n ...disabledButton(render, disabled).props,\n onPointerDown: (event: PointerEvent<HTMLButtonElement>) => {\n event.preventDefault();\n },\n onMouseDown: (event: MouseEvent<HTMLButtonElement>) => {\n event.preventDefault();\n },\n onClick: (event: MouseEvent<HTMLButtonElement>) => {\n if (disabled) {\n // A disabled link must not navigate either.\n event.preventDefault();\n return;\n }\n ctx.clear(event.nativeEvent);\n },\n \"data-disabled\": dataAttr(disabled),\n };\n\n return useRender<ComponentPropsWithRef<\"button\">, ComboboxClearState>({\n defaultElement: \"button\",\n render,\n state,\n className,\n style,\n children,\n props: rest,\n libraryProps,\n ref,\n });\n}\n\nComboboxClear.displayName = \"ComboboxClear\";\n"],"mappings":";;;;;;;AAeA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;;;;;;;;;;;;AA4DvC,SAAgB,cAAc,EAC5B,UAAU,cAAc,OACxB,WACA,OACA,UACA,QACA,GAAG,QACkB;CACrB,MAAM,MAAM,mBAAmB,gBAAgB;CAC/C,MAAM,WAAW,eAAe,IAAI;CACpC,MAAM,MAAM,eACV,SAAS,+EACT,WACF;CACA,MAAM,QAA4B;EAAE,OAAO,IAAI;EAAO,YAAY,IAAI;EAAY;CAAS;CAE3F,MAAM,eAAiE;EACrE,GAAI,cAAc,MAAM,KAAK,EAAE,MAAM,SAAkB;EACvD,UAAU;EACV,GAAG,eAAe,QAAQ,QAAQ,CAAC,CAAC;EACpC,gBAAgB,UAA2C;GACzD,MAAM,eAAe;EACvB;EACA,cAAc,UAAyC;GACrD,MAAM,eAAe;EACvB;EACA,UAAU,UAAyC;GACjD,IAAI,UAAU;IAEZ,MAAM,eAAe;IACrB;GACF;GACA,IAAI,MAAM,MAAM,WAAW;EAC7B;EACA,iBAAiB,SAAS,QAAQ;CACpC;CAEA,OAAO,UAA+D;EACpE,gBAAgB;EAChB;EACA;EACA;EACA;EACA;EACA,OAAO;EACP;EACA;CACF,CAAC;AACH;AAEA,cAAc,cAAc"}
1
+ {"version":3,"file":"combobox-clear.mjs","names":[],"sources":["../../src/combobox/combobox-clear.tsx"],"sourcesContent":["\"use client\";\nimport type {\n ComponentPropsWithRef,\n CSSProperties,\n MouseEvent,\n PointerEvent,\n ReactNode,\n} from \"react\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { BUTTON_NAME, useNameWarning } from \"../internal/use-name-warning.js\";\nimport { disabledButton, rendersButton, useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport { useComboboxContext } from \"./combobox-context.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/**\n * State of `Combobox.Clear`, passed to the function forms of `className`, `style`, `children` and\n * `render`.\n */\nexport interface ComboboxClearState {\n /** Optimistic selection; always `null` with `multiple` (read `values`). */\n readonly value: string | null;\n /** Optimistic selection as a list: pick order with `multiple`, `[value]` or `[]` otherwise. */\n readonly values: readonly string[];\n /** The text in the input (urgent). */\n readonly inputValue: string;\n /** Disabled by its own prop or by the Root. */\n readonly disabled: boolean;\n}\n\n/**\n * Props of `Combobox.Clear`.\n *\n * @see https://ui.funstack.work/components/combobox\n */\nexport interface ComboboxClearProps extends Omit<\n ComponentPropsWithRef<\"button\">,\n | \"onClick\"\n | \"onPointerDown\"\n | \"onMouseDown\"\n | \"tabIndex\"\n | \"disabled\"\n | \"className\"\n | \"style\"\n | \"children\"\n> {\n /**\n * Disables this button; the Root's `disabled` does too. Native `disabled` on a `<button>`; with\n * a link or component `render`, `aria-disabled=\"true\"` instead.\n *\n * @defaultValue `false`\n */\n disabled?: boolean;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, ComboboxClearState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, ComboboxClearState>;\n /** Content, or a function of the part's state. */\n children?: StateValue<ReactNode, ComboboxClearState>;\n /** Should render a `<button>`. */\n render?: RenderProp<ComponentPropsWithRef<\"button\">, ComboboxClearState>;\n}\n\n/**\n * The optional button that clears the combobox: `<button type=\"button\" tabindex=\"-1\">`. A click\n * empties the text (urgent) and dispatches `valueChangeAction(null)` (with `multiple`: one change\n * that removes every value, announced) unless nothing is selected;\n * the input keeps focus. Always rendered: hide it with CSS (`:placeholder-shown`) or `state`.\n * A click while the listbox is open closes it (the platform's light dismiss: the button is\n * outside the popup).\n *\n * Owned keys: `type` (on a `<button>`), `tabIndex`, `disabled`, `aria-disabled` (link or component\n * `render`), `onClick`, `onPointerDown`, `onMouseDown`, `data-disabled`.\n *\n * @see https://ui.funstack.work/components/combobox\n */\nexport function ComboboxClear({\n disabled: ownDisabled = false,\n className,\n style,\n children,\n render,\n ...rest\n}: ComboboxClearProps) {\n const ctx = useComboboxContext(\"Combobox.Clear\");\n const disabled = ownDisabled || ctx.disabled;\n const ref = useNameWarning(\n isDev && \"Combobox.Clear: the button has no accessible name. Give it an `aria-label`.\",\n BUTTON_NAME,\n );\n const state: ComboboxClearState = {\n value: ctx.value,\n values: ctx.values,\n inputValue: ctx.inputValue,\n disabled,\n };\n\n const libraryProps: ComponentPropsWithRef<\"button\"> & DataAttributes = {\n ...(rendersButton(render) && { type: \"button\" as const }),\n tabIndex: -1,\n ...disabledButton(render, disabled).props,\n onPointerDown: (event: PointerEvent<HTMLButtonElement>) => {\n event.preventDefault();\n },\n onMouseDown: (event: MouseEvent<HTMLButtonElement>) => {\n event.preventDefault();\n },\n onClick: (event: MouseEvent<HTMLButtonElement>) => {\n if (disabled) {\n // A disabled link must not navigate either.\n event.preventDefault();\n return;\n }\n ctx.clear(event.nativeEvent);\n },\n \"data-disabled\": dataAttr(disabled),\n };\n\n return useRender<ComponentPropsWithRef<\"button\">, ComboboxClearState>({\n defaultElement: \"button\",\n render,\n state,\n className,\n style,\n children,\n props: rest,\n libraryProps,\n ref,\n });\n}\n\nComboboxClear.displayName = \"ComboboxClear\";\n"],"mappings":";;;;;;;AAeA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;;;;;;;;;;;;;AA+DvC,SAAgB,cAAc,EAC5B,UAAU,cAAc,OACxB,WACA,OACA,UACA,QACA,GAAG,QACkB;CACrB,MAAM,MAAM,mBAAmB,gBAAgB;CAC/C,MAAM,WAAW,eAAe,IAAI;CACpC,MAAM,MAAM,eACV,SAAS,+EACT,WACF;CACA,MAAM,QAA4B;EAChC,OAAO,IAAI;EACX,QAAQ,IAAI;EACZ,YAAY,IAAI;EAChB;CACF;CAEA,MAAM,eAAiE;EACrE,GAAI,cAAc,MAAM,KAAK,EAAE,MAAM,SAAkB;EACvD,UAAU;EACV,GAAG,eAAe,QAAQ,QAAQ,CAAC,CAAC;EACpC,gBAAgB,UAA2C;GACzD,MAAM,eAAe;EACvB;EACA,cAAc,UAAyC;GACrD,MAAM,eAAe;EACvB;EACA,UAAU,UAAyC;GACjD,IAAI,UAAU;IAEZ,MAAM,eAAe;IACrB;GACF;GACA,IAAI,MAAM,MAAM,WAAW;EAC7B;EACA,iBAAiB,SAAS,QAAQ;CACpC;CAEA,OAAO,UAA+D;EACpE,gBAAgB;EAChB;EACA;EACA;EACA;EACA;EACA,OAAO;EACP;EACA;CACF,CAAC;AACH;AAEA,cAAc,cAAc"}
@@ -1,4 +1,5 @@
1
1
  "use client";
2
+ import { optionId } from "../internal/use-option-registry.mjs";
2
3
  import { createContext, use } from "react";
3
4
  //#region src/combobox/combobox-context.ts
4
5
  const ComboboxContext = createContext(null);
@@ -13,11 +14,9 @@ const ComboboxPopupContext = createContext(false);
13
14
  const ComboboxListContext = createContext(false);
14
15
  /** `Combobox.Group`: the id its `Combobox.GroupLabel` renders. */
15
16
  const ComboboxGroupContext = createContext(null);
16
- /** The id fragment of an option value: stable across result sets, no whitespace (design 3.5). */
17
- function optionId(prefix, value) {
18
- return `${prefix}${encodeURIComponent(value)}`;
19
- }
17
+ /** `Combobox.Chip`: its value, for the `Combobox.ChipRemove` inside it. */
18
+ const ComboboxChipContext = createContext(null);
20
19
  //#endregion
21
- export { ComboboxContext, ComboboxGroupContext, ComboboxListContext, ComboboxPopupContext, optionId, useComboboxContext };
20
+ export { ComboboxChipContext, ComboboxContext, ComboboxGroupContext, ComboboxListContext, ComboboxPopupContext, optionId, useComboboxContext };
22
21
 
23
22
  //# sourceMappingURL=combobox-context.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"combobox-context.mjs","names":[],"sources":["../../src/combobox/combobox-context.ts"],"sourcesContent":["\"use client\";\nimport { createContext, use } from \"react\";\nimport type { RefObject } from \"react\";\nimport type { PopoverRootValue } from \"../internal/overlay/use-overlay-root.js\";\n\n/** What a mounted `Combobox.Option` tells its Root (design 2, \"mounted options, labels\"). */\nexport interface ComboboxOptionEntry {\n readonly element: HTMLElement;\n /** The `label` prop; `undefined`: the element's trimmed `textContent` at the moment of use. */\n readonly label: string | undefined;\n readonly disabled: boolean;\n}\n\n/** One Combobox: what its Root provides to every part (design 14, `combobox-context.ts`). */\nexport interface ComboboxContextValue {\n /** The shared popover machinery (`usePopoverRoot`, library mode). */\n readonly popover: PopoverRootValue;\n readonly ids: {\n readonly input: string;\n readonly label: string;\n readonly list: string;\n /** `${root}-option-`: an Option's id is this plus `encodeURIComponent(value)`. */\n readonly optionPrefix: string;\n };\n /** Optimistic selection. */\n readonly value: string | null;\n /** The `valueChangeAction` transition is in flight. */\n readonly valuePending: boolean;\n /** `valuePending` or the open transition is in flight (the Root's `pending`). */\n readonly pending: boolean;\n /** The urgent text. */\n readonly inputValue: string;\n /** `useDeferredValue(inputValue)`: what the mounted results are for. */\n readonly query: string;\n readonly stale: boolean;\n /** The option `aria-activedescendant` points at (urgent virtual focus), or `null`. */\n readonly activeValue: string | null;\n /** No option is mounted and the results are settled (`Empty`, `data-empty`). */\n readonly empty: boolean;\n /** A `Combobox.Status` is mounted inside the List (a Suspense fallback): results are loading. */\n readonly loading: boolean;\n /** A `Combobox.Label` is mounted (the List's `aria-labelledby` names it only then). */\n readonly hasLabel: boolean;\n /** The enclosing `Field.Label`'s id: names the List when no `Combobox.Label` is mounted. */\n readonly fieldLabelId: string | undefined;\n readonly disabled: boolean;\n readonly inputRef: RefObject<HTMLInputElement | null>;\n readonly listRef: RefObject<HTMLElement | null>;\n /** Registers a mounted Option; returns the unregistration. */\n readonly registerOption: (value: string, entry: ComboboxOptionEntry) => () => void;\n /** Registers a mounted `Combobox.Status`; while one is mounted the results count as loading. */\n readonly registerStatus: () => () => void;\n /** Registers a mounted `Combobox.Label`; returns the unregistration. */\n readonly registerLabel: () => () => void;\n /** Make `value` the active option (urgent; never dispatches). */\n readonly setActive: (value: string | null) => void;\n /** Accept an option (design 5.2): urgent text write, dispatch, close when it settles. */\n readonly accept: (value: string, event: Event) => void;\n /** `Combobox.Clear` (design 3.3). */\n readonly clear: (event: Event) => void;\n /** The `change` of the Input: urgent text write and an open request (design 2.2, 5.1). */\n readonly typed: (text: string, event: Event) => void;\n /** Keyboard model of design section 8, run by the Input's `onKeyDown`. */\n readonly keyDown: (event: KeyboardEvent) => boolean;\n /** Focus arrived in the Input: track presses until a leave is decided. */\n readonly focusIn: (event: FocusEvent) => void;\n /** Focus left the Input (design 5.4): close at once, then revert or commit free text. */\n readonly focusOut: (event: FocusEvent) => void;\n /** A pointer click in the Input (`openOnClick`). */\n readonly inputClick: (event: MouseEvent) => void;\n /** A press on the Input: captures the pointer to the shown Popup (design 5.4). */\n readonly inputPointerDown: (event: PointerEvent) => void;\n}\n\nexport const ComboboxContext = createContext<ComboboxContextValue | null>(null);\n\nexport function useComboboxContext(part: string): ComboboxContextValue {\n const context = use(ComboboxContext);\n if (context === null) {\n throw new Error(`${part} must be rendered inside a Combobox.Root.`);\n }\n return context;\n}\n\n/** Provided by `Combobox.Popup` (a List outside a Popup warns). */\nexport const ComboboxPopupContext = createContext<boolean>(false);\n\n/** Provided by `Combobox.List` (an Option outside a List warns). */\nexport const ComboboxListContext = createContext<boolean>(false);\n\n/** `Combobox.Group`: the id its `Combobox.GroupLabel` renders. */\nexport const ComboboxGroupContext = createContext<string | null>(null);\n\n/** The id fragment of an option value: stable across result sets, no whitespace (design 3.5). */\nexport function optionId(prefix: string, value: string): string {\n return `${prefix}${encodeURIComponent(value)}`;\n}\n"],"mappings":";;;AA0EA,MAAa,kBAAkB,cAA2C,IAAI;AAE9E,SAAgB,mBAAmB,MAAoC;CACrE,MAAM,UAAU,IAAI,eAAe;CACnC,IAAI,YAAY,MACd,MAAM,IAAI,MAAM,GAAG,KAAK,0CAA0C;CAEpE,OAAO;AACT;;AAGA,MAAa,uBAAuB,cAAuB,KAAK;;AAGhE,MAAa,sBAAsB,cAAuB,KAAK;;AAG/D,MAAa,uBAAuB,cAA6B,IAAI;;AAGrE,SAAgB,SAAS,QAAgB,OAAuB;CAC9D,OAAO,GAAG,SAAS,mBAAmB,KAAK;AAC7C"}
1
+ {"version":3,"file":"combobox-context.mjs","names":[],"sources":["../../src/combobox/combobox-context.ts"],"sourcesContent":["\"use client\";\nimport { createContext, use } from \"react\";\nimport type { RefObject } from \"react\";\nimport type { PopoverRootValue } from \"../internal/overlay/use-overlay-root.js\";\nimport type { ListboxOptionEntry } from \"../internal/use-option-registry.js\";\n\nexport { optionId } from \"../internal/use-option-registry.js\";\n\n/** What a mounted `Combobox.Option` tells its Root (design 2, \"mounted options, labels\"). */\nexport type ComboboxOptionEntry = ListboxOptionEntry;\n\n/** One Combobox: what its Root provides to every part (design 14, `combobox-context.ts`). */\nexport interface ComboboxContextValue {\n /** The shared popover machinery (`usePopoverRoot`, library mode). */\n readonly popover: PopoverRootValue;\n readonly ids: {\n readonly input: string;\n readonly label: string;\n readonly list: string;\n /** `${root}-option-`: an Option's id is this plus `encodeURIComponent(value)`. */\n readonly optionPrefix: string;\n };\n /** Optimistic selection; always `null` with `multiple` (design 15.2). */\n readonly value: string | null;\n /** `multiple` at mount (design 15). */\n readonly multiple: boolean;\n /** Optimistic selection as a list: pick order with `multiple`, `[value]` or `[]` otherwise. */\n readonly values: readonly string[];\n /** `value` is in the optimistic selection (`aria-selected`, `data-selected`). */\n readonly isSelected: (value: string) => boolean;\n /**\n * `data-pending` of an Option, Chip or ChipRemove: the value action is in flight and `value`\n * is its optimistic target (single, design 5.2), or its optimistic and committed membership\n * differ (`multiple`, design 15.5).\n */\n readonly isPending: (value: string) => boolean;\n /** The `valueChangeAction` transition is in flight. */\n readonly valuePending: boolean;\n /** `valuePending` or the open transition is in flight (the Root's `pending`). */\n readonly pending: boolean;\n /** The urgent text. */\n readonly inputValue: string;\n /** `useDeferredValue(inputValue)`: what the mounted results are for. */\n readonly query: string;\n readonly stale: boolean;\n /** The option `aria-activedescendant` points at (urgent virtual focus), or `null`. */\n readonly activeValue: string | null;\n /** No option is mounted and the results are settled (`Empty`, `data-empty`). */\n readonly empty: boolean;\n /** A `Combobox.Status` is mounted inside the List (a Suspense fallback): results are loading. */\n readonly loading: boolean;\n /** A `Combobox.Label` is mounted (the List's `aria-labelledby` names it only then). */\n readonly hasLabel: boolean;\n /** The enclosing `Field.Label`'s id: names the List when no `Combobox.Label` is mounted. */\n readonly fieldLabelId: string | undefined;\n readonly disabled: boolean;\n readonly inputRef: RefObject<HTMLInputElement | null>;\n readonly listRef: RefObject<HTMLElement | null>;\n /** Registers a mounted Option; returns the unregistration. */\n readonly registerOption: (value: string, entry: ComboboxOptionEntry) => () => void;\n /** Registers a mounted `Combobox.Status`; while one is mounted the results count as loading. */\n readonly registerStatus: () => () => void;\n /** Registers a mounted `Combobox.Label`; returns the unregistration. */\n readonly registerLabel: () => () => void;\n /** Make `value` the active option (urgent; never dispatches). */\n readonly setActive: (value: string | null) => void;\n /** Accept an option (design 5.2): urgent text write, dispatch, close when it settles. */\n readonly accept: (value: string, event: Event) => void;\n /** `Combobox.Clear` (design 3.3). */\n readonly clear: (event: Event) => void;\n /** The `change` of the Input: urgent text write and an open request (design 2.2, 5.1). */\n readonly typed: (text: string, event: Event) => void;\n /** Keyboard model of design section 8, run by the Input's `onKeyDown`. */\n readonly keyDown: (event: KeyboardEvent) => boolean;\n /** Focus arrived in the Input: track presses until a leave is decided. */\n readonly focusIn: (event: FocusEvent) => void;\n /** Focus left the Input (design 5.4): close at once, then revert or commit free text. */\n readonly focusOut: (event: FocusEvent) => void;\n /** A pointer click in the Input (`openOnClick`). */\n readonly inputClick: (event: MouseEvent) => void;\n /** A press on the Input: captures the pointer to the shown Popup (design 5.4). */\n readonly inputPointerDown: (event: PointerEvent) => void;\n /** The chips of `multiple` (design 15); inert without it. */\n readonly chips: ComboboxChipsValue;\n}\n\n/** What a mounted `Combobox.Chip` tells its Root (design 15.6, 15.7). */\nexport interface ComboboxChipEntry {\n readonly element: HTMLElement;\n /** The Chip's `label` prop. */\n readonly label: string | undefined;\n}\n\n/** The chips half of the Root's context (design 15). */\nexport interface ComboboxChipsValue {\n /** The `Combobox.Chips` element: inside the combobox for the leave rule (design 15.6). */\n readonly chipsRef: RefObject<HTMLElement | null>;\n /** The label cache's entry for `value` (design 15.1), from render state. */\n readonly labelOf: (value: string) => string | undefined;\n /** Registers a mounted Chip; returns the unregistration. */\n readonly registerChip: (value: string, entry: ComboboxChipEntry) => () => void;\n /** Registers a mounted `ChipRemove` element (skipped in a chip's announced text). */\n readonly registerRemove: (element: Element) => () => void;\n /** `Combobox.ChipRemove`'s click: remove `value`, announce it, focus the Input. */\n readonly removeChip: (value: string, event: Event) => void;\n /** The keys of a focused chip (design 15.6), run by `Chips`' `onKeyDown`. */\n readonly keyDown: (event: KeyboardEvent) => void;\n /** Focus arrived in `Chips` (on a chip): the listbox closes (design 15.6). */\n readonly focusIn: (event: FocusEvent) => void;\n /** Focus left a chip. */\n readonly focusOut: (event: FocusEvent) => void;\n /** A click in `Chips`: the Input takes focus (design 15.6). */\n readonly click: (event: MouseEvent) => void;\n}\n\nexport const ComboboxContext = createContext<ComboboxContextValue | null>(null);\n\nexport function useComboboxContext(part: string): ComboboxContextValue {\n const context = use(ComboboxContext);\n if (context === null) {\n throw new Error(`${part} must be rendered inside a Combobox.Root.`);\n }\n return context;\n}\n\n/** Provided by `Combobox.Popup` (a List outside a Popup warns). */\nexport const ComboboxPopupContext = createContext<boolean>(false);\n\n/** Provided by `Combobox.List` (an Option outside a List warns). */\nexport const ComboboxListContext = createContext<boolean>(false);\n\n/** `Combobox.Group`: the id its `Combobox.GroupLabel` renders. */\nexport const ComboboxGroupContext = createContext<string | null>(null);\n\n/** `Combobox.Chip`: its value, for the `Combobox.ChipRemove` inside it. */\nexport const ComboboxChipContext = createContext<string | null>(null);\n"],"mappings":";;;;AAmHA,MAAa,kBAAkB,cAA2C,IAAI;AAE9E,SAAgB,mBAAmB,MAAoC;CACrE,MAAM,UAAU,IAAI,eAAe;CACnC,IAAI,YAAY,MACd,MAAM,IAAI,MAAM,GAAG,KAAK,0CAA0C;CAEpE,OAAO;AACT;;AAGA,MAAa,uBAAuB,cAAuB,KAAK;;AAGhE,MAAa,sBAAsB,cAAuB,KAAK;;AAG/D,MAAa,uBAAuB,cAA6B,IAAI;;AAGrE,MAAa,sBAAsB,cAA6B,IAAI"}
@@ -3,8 +3,10 @@ import { CSSProperties, ComponentPropsWithRef } from "react";
3
3
  //#region src/combobox/combobox-input.d.ts
4
4
  /** State of `Combobox.Input`, passed to the function forms of `className`, `style` and `render`. */
5
5
  export interface ComboboxInputState {
6
- /** Optimistic selection. */
6
+ /** Optimistic selection; always `null` with `multiple` (read `values`). */
7
7
  readonly value: string | null;
8
+ /** Optimistic selection as a list: pick order with `multiple`, `[value]` or `[]` otherwise. */
9
+ readonly values: readonly string[];
8
10
  /** The urgent text. */
9
11
  readonly inputValue: string;
10
12
  /** Optimistic open state. */
@@ -22,7 +24,11 @@ export interface ComboboxInputState {
22
24
  * @see https://ui.funstack.work/components/combobox
23
25
  */
24
26
  export interface ComboboxInputProps extends Omit<ComponentPropsWithRef<"input">, "value" | "defaultValue" | "onChange" | "onInput" | "onKeyDown" | "onFocus" | "onBlur" | "onClick" | "onPointerDown" | "role" | "aria-autocomplete" | "aria-expanded" | "aria-controls" | "aria-activedescendant" | "autoComplete" | "disabled" | "className" | "style" | "children"> {
25
- /** Native `required`: empty text is `valueMissing`. */
27
+ /**
28
+ * Native `required`: empty text is `valueMissing`. With `multiple` it means "at least one
29
+ * value": native `required` is rendered only while the selection is empty, and
30
+ * `aria-required="true"` always.
31
+ */
26
32
  required?: boolean;
27
33
  /** Class name, or a function of the part's state that returns one. */
28
34
  className?: StateValue<string | undefined, ComboboxInputState>;
@@ -43,7 +49,8 @@ export interface ComboboxInputProps extends Omit<ComponentPropsWithRef<"input">,
43
49
  * listbox is shown captures the pointer to the Popup, so it is no light dismiss), `data-open`,
44
50
  * `data-pending`, `data-selected`, `data-stale`, `data-disabled`; inside a `Field.Root` (whose
45
51
  * control id it takes) also `required` (own or the Field's), `aria-describedby` (token-merged),
46
- * `aria-invalid` and `data-invalid`. `onFocusCapture` passes through.
52
+ * `aria-invalid` and `data-invalid`; with `multiple`, `required` (only while nothing is selected)
53
+ * and `aria-required`. `onFocusCapture` passes through.
47
54
  *
48
55
  * @see https://ui.funstack.work/components/combobox
49
56
  */
@@ -1 +1 @@
1
- {"version":3,"file":"combobox-input.d.mts","names":[],"sources":["../../src/combobox/combobox-input.tsx"],"mappings":";;;;iBAwBiB;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;;;;;;iBAQM,2BAA2B,KAC1C;;EAsBA;;EAEA,YAAY,+BAA+B;;EAE3C,QAAQ,WAAW,2BAA2B;;EAE9C,SAAS,WAAW,gCAAgC;;;;;;;;;;;;;;;;;;wBAmBtC,gBAAgB,WAAW,OAAO,WAAW,QAAQ,qCAAkB;yBAAvE"}
1
+ {"version":3,"file":"combobox-input.d.mts","names":[],"sources":["../../src/combobox/combobox-input.tsx"],"mappings":";;;;iBAwBiB;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;;;;;;iBAQM,2BAA2B,KAC1C;;;;;;EA0BA;;EAEA,YAAY,+BAA+B;;EAE3C,QAAQ,WAAW,2BAA2B;;EAE9C,SAAS,WAAW,gCAAgC;;;;;;;;;;;;;;;;;;;wBAoBtC,gBAAgB,WAAW,OAAO,WAAW,QAAQ,qCAAkB;yBAAvE"}
@@ -3,9 +3,10 @@ import { dataAttr } from "../internal/data-attr.mjs";
3
3
  import { useRender } from "../internal/use-render.mjs";
4
4
  import { useElementCheck } from "../internal/use-element-check.mjs";
5
5
  import { useMergedRefs } from "../internal/use-merged-refs.mjs";
6
- import { useFieldControl } from "../internal/form/use-field-control.mjs";
7
6
  import { registerTrigger } from "../internal/overlay/trigger-ref.mjs";
8
- import { optionId, useComboboxContext } from "./combobox-context.mjs";
7
+ import { useFieldControl } from "../internal/form/use-field-control.mjs";
8
+ import { optionId } from "../internal/use-option-registry.mjs";
9
+ import { useComboboxContext } from "./combobox-context.mjs";
9
10
  import { isValidElement, useCallback } from "react";
10
11
  //#region src/combobox/combobox-input.tsx
11
12
  const isDev = process.env.NODE_ENV !== "production";
@@ -21,7 +22,8 @@ const isDev = process.env.NODE_ENV !== "production";
21
22
  * listbox is shown captures the pointer to the Popup, so it is no light dismiss), `data-open`,
22
23
  * `data-pending`, `data-selected`, `data-stale`, `data-disabled`; inside a `Field.Root` (whose
23
24
  * control id it takes) also `required` (own or the Field's), `aria-describedby` (token-merged),
24
- * `aria-invalid` and `data-invalid`. `onFocusCapture` passes through.
25
+ * `aria-invalid` and `data-invalid`; with `multiple`, `required` (only while nothing is selected)
26
+ * and `aria-required`. `onFocusCapture` passes through.
25
27
  *
26
28
  * @see https://ui.funstack.work/components/combobox
27
29
  */
@@ -31,6 +33,7 @@ function ComboboxInput({ className, style, render, ...rest }) {
31
33
  const { triggerRef } = popover;
32
34
  const state = {
33
35
  value: ctx.value,
36
+ values: ctx.values,
34
37
  inputValue: ctx.inputValue,
35
38
  open: popover.optimistic,
36
39
  pending: ctx.pending,
@@ -64,9 +67,14 @@ function ComboboxInput({ className, style, render, ...rest }) {
64
67
  const fieldRef = field.ref;
65
68
  const mergedRef = useMergedRefs(ref, fieldRef);
66
69
  const searchType = isValidElement(render) && render.props.type === "search";
70
+ const required = field.inField ? field.required : rest.required === true;
71
+ const requiredProps = ctx.multiple ? {
72
+ required: required && ctx.values.length === 0,
73
+ "aria-required": required || void 0
74
+ } : field.inField && { required: field.required };
67
75
  const libraryProps = {
68
76
  ...field.attributes,
69
- ...field.inField && { required: field.required },
77
+ ...requiredProps,
70
78
  id: ids.input,
71
79
  type: searchType ? "search" : "text",
72
80
  role: "combobox",
@@ -97,7 +105,7 @@ function ComboboxInput({ className, style, render, ...rest }) {
97
105
  },
98
106
  "data-open": dataAttr(popover.optimistic),
99
107
  "data-pending": dataAttr(state.pending),
100
- "data-selected": dataAttr(ctx.value !== null),
108
+ "data-selected": dataAttr(ctx.values.length > 0),
101
109
  "data-stale": dataAttr(ctx.stale),
102
110
  "data-disabled": dataAttr(ctx.disabled)
103
111
  };
@@ -1 +1 @@
1
- {"version":3,"file":"combobox-input.mjs","names":[],"sources":["../../src/combobox/combobox-input.tsx"],"sourcesContent":["\"use client\";\nimport { isValidElement, useCallback } from \"react\";\nimport type {\n ChangeEvent,\n ComponentPropsWithRef,\n CSSProperties,\n FocusEvent,\n KeyboardEvent,\n MouseEvent,\n PointerEvent,\n} from \"react\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { registerTrigger } from \"../internal/overlay/trigger-ref.js\";\nimport { useElementCheck } from \"../internal/use-element-check.js\";\nimport { useFieldControl } from \"../internal/form/use-field-control.js\";\nimport { useMergedRefs } from \"../internal/use-merged-refs.js\";\nimport { useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport { optionId, useComboboxContext } from \"./combobox-context.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/** State of `Combobox.Input`, passed to the function forms of `className`, `style` and `render`. */\nexport interface ComboboxInputState {\n /** Optimistic selection. */\n readonly value: string | null;\n /** The urgent text. */\n readonly inputValue: string;\n /** Optimistic open state. */\n readonly open: boolean;\n /** The Root is pending (a selection or an open in flight). */\n readonly pending: boolean;\n /** The results shown are for an older text. */\n readonly stale: boolean;\n /** The Root's `disabled` (or the Field's). */\n readonly disabled: boolean;\n}\n\n/**\n * Props of `Combobox.Input`.\n *\n * @see https://ui.funstack.work/components/combobox\n */\nexport interface ComboboxInputProps extends Omit<\n ComponentPropsWithRef<\"input\">,\n | \"value\"\n | \"defaultValue\"\n | \"onChange\"\n | \"onInput\"\n | \"onKeyDown\"\n | \"onFocus\"\n | \"onBlur\"\n | \"onClick\"\n | \"onPointerDown\"\n | \"role\"\n | \"aria-autocomplete\"\n | \"aria-expanded\"\n | \"aria-controls\"\n | \"aria-activedescendant\"\n | \"autoComplete\"\n | \"disabled\"\n | \"className\"\n | \"style\"\n | \"children\"\n> {\n /** Native `required`: empty text is `valueMissing`. */\n required?: boolean;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, ComboboxInputState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, ComboboxInputState>;\n /** Must render an `<input>` of type `text` or `search`. */\n render?: RenderProp<ComponentPropsWithRef<\"input\">, ComboboxInputState>;\n}\n\n/**\n * The text field: `<input role=\"combobox\" aria-autocomplete=\"list\" aria-expanded aria-controls\n * aria-activedescendant autocomplete=\"off\">`. DOM focus stays here while the active option moves\n * virtually (design 7.1). Its text is the Root's urgent `inputValue`; typing opens the listbox.\n *\n * Owned keys (conventions 1.2): `id`, `type`, `role`, `value`, `autoComplete`,\n * `aria-autocomplete`, `aria-expanded`, `aria-controls` (token-merged), `aria-activedescendant`,\n * `disabled`, `onChange`, `onKeyDown`, `onFocus` and `onBlur` (focus arriving starts the press\n * watch that decides a focus loss), `onClick`, `onPointerDown` (a primary-button press while the\n * listbox is shown captures the pointer to the Popup, so it is no light dismiss), `data-open`,\n * `data-pending`, `data-selected`, `data-stale`, `data-disabled`; inside a `Field.Root` (whose\n * control id it takes) also `required` (own or the Field's), `aria-describedby` (token-merged),\n * `aria-invalid` and `data-invalid`. `onFocusCapture` passes through.\n *\n * @see https://ui.funstack.work/components/combobox\n */\nexport function ComboboxInput({ className, style, render, ...rest }: ComboboxInputProps) {\n const ctx = useComboboxContext(\"Combobox.Input\");\n const { popover, ids, inputRef } = ctx;\n const { triggerRef } = popover;\n\n const state: ComboboxInputState = {\n value: ctx.value,\n inputValue: ctx.inputValue,\n open: popover.optimistic,\n pending: ctx.pending,\n stale: ctx.stale,\n disabled: ctx.disabled,\n };\n\n const checkElement = useElementCheck(\n isDev &&\n ((element) => {\n const type = element.tagName === \"INPUT\" ? (element as HTMLInputElement).type : \"\";\n return type !== \"text\" && type !== \"search\"\n ? `Combobox.Input: rendered <${element.tagName.toLowerCase()}` +\n `${type === \"\" ? \"\" : ` type=\"${type}\"`}>. Render an <input> of type \"text\" or ` +\n '\"search\": `role=\"combobox\"`, `aria-activedescendant` and the caret keys depend on it.'\n : null;\n }),\n );\n const ref = useCallback(\n (element: HTMLElement) => {\n checkElement?.(element);\n inputRef.current = element as HTMLInputElement;\n // The popover's \"trigger\" is the input: `showPopover({ source: input })` anchors the\n // listbox to it and stacks a nested listbox under its popover (design 5.1). It does not\n // exempt presses on the input from light dismiss; `onPointerDown` does that.\n const unregister = registerTrigger(triggerRef, element, \"Combobox.Input\");\n return () => {\n if (inputRef.current === element) inputRef.current = null;\n unregister();\n };\n },\n [checkElement, inputRef, triggerRef],\n );\n\n // Inside a Field.Root (design/components/field-form.md 7.2) the Input is the Field's control:\n // the Root already took the Field's id for it; `required` and the ARIA wiring land here.\n const field = useFieldControl({\n labelable: true,\n required: rest.required,\n disabled: ctx.disabled,\n id: rest.id,\n component: \"Combobox.Input\",\n });\n const fieldRef = field.ref;\n const mergedRef = useMergedRefs<HTMLElement>(ref, fieldRef);\n\n const searchType = isValidElement<{ type?: unknown }>(render) && render.props.type === \"search\";\n\n const libraryProps: ComponentPropsWithRef<\"input\"> & DataAttributes = {\n ...field.attributes,\n ...(field.inField && { required: field.required }),\n id: ids.input,\n type: searchType ? \"search\" : \"text\",\n role: \"combobox\",\n value: ctx.inputValue,\n autoComplete: \"off\",\n \"aria-autocomplete\": \"list\",\n // Shown (the listbox is in the top layer); `data-open` is the optimistic one.\n \"aria-expanded\": popover.shown,\n \"aria-controls\": ids.list,\n \"aria-activedescendant\":\n ctx.activeValue === null ? undefined : optionId(ids.optionPrefix, ctx.activeValue),\n disabled: ctx.disabled,\n onChange: (event: ChangeEvent<HTMLInputElement>) => {\n ctx.typed(event.currentTarget.value, event.nativeEvent);\n },\n onKeyDown: (event: KeyboardEvent<HTMLInputElement>) => {\n ctx.keyDown(event.nativeEvent);\n },\n onFocus: (event: FocusEvent<HTMLInputElement>) => {\n ctx.focusIn(event.nativeEvent);\n },\n onBlur: (event: FocusEvent<HTMLInputElement>) => {\n ctx.focusOut(event.nativeEvent);\n },\n onClick: (event: MouseEvent<HTMLInputElement>) => {\n ctx.inputClick(event.nativeEvent);\n },\n onPointerDown: (event: PointerEvent<HTMLInputElement>) => {\n ctx.inputPointerDown(event.nativeEvent);\n },\n \"data-open\": dataAttr(popover.optimistic),\n \"data-pending\": dataAttr(state.pending),\n \"data-selected\": dataAttr(ctx.value !== null),\n \"data-stale\": dataAttr(ctx.stale),\n \"data-disabled\": dataAttr(ctx.disabled),\n };\n\n return useRender<ComponentPropsWithRef<\"input\">, ComboboxInputState>({\n defaultElement: \"input\",\n render,\n state,\n className,\n style,\n children: undefined,\n props: rest,\n libraryProps,\n ref: mergedRef,\n });\n}\n\nComboboxInput.displayName = \"ComboboxInput\";\n"],"mappings":";;;;;;;;;;AAqBA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;;;;;;;;;;;;;;;;AAuEvC,SAAgB,cAAc,EAAE,WAAW,OAAO,QAAQ,GAAG,QAA4B;CACvF,MAAM,MAAM,mBAAmB,gBAAgB;CAC/C,MAAM,EAAE,SAAS,KAAK,aAAa;CACnC,MAAM,EAAE,eAAe;CAEvB,MAAM,QAA4B;EAChC,OAAO,IAAI;EACX,YAAY,IAAI;EAChB,MAAM,QAAQ;EACd,SAAS,IAAI;EACb,OAAO,IAAI;EACX,UAAU,IAAI;CAChB;CAEA,MAAM,eAAe,gBACnB,WACI,YAAY;EACZ,MAAM,OAAO,QAAQ,YAAY,UAAW,QAA6B,OAAO;EAChF,OAAO,SAAS,UAAU,SAAS,WAC/B,6BAA6B,QAAQ,QAAQ,YAAY,IACpD,SAAS,KAAK,KAAK,UAAU,KAAK,GAAG,oIAE1C;CACN,EACJ;CACA,MAAM,MAAM,aACT,YAAyB;EACxB,eAAe,OAAO;EACtB,SAAS,UAAU;EAInB,MAAM,aAAa,gBAAgB,YAAY,SAAS,gBAAgB;EACxE,aAAa;GACX,IAAI,SAAS,YAAY,SAAS,SAAS,UAAU;GACrD,WAAW;EACb;CACF,GACA;EAAC;EAAc;EAAU;CAAU,CACrC;CAIA,MAAM,QAAQ,gBAAgB;EAC5B,WAAW;EACX,UAAU,KAAK;EACf,UAAU,IAAI;EACd,IAAI,KAAK;EACT,WAAW;CACb,CAAC;CACD,MAAM,WAAW,MAAM;CACvB,MAAM,YAAY,cAA2B,KAAK,QAAQ;CAE1D,MAAM,aAAa,eAAmC,MAAM,KAAK,OAAO,MAAM,SAAS;CAEvF,MAAM,eAAgE;EACpE,GAAG,MAAM;EACT,GAAI,MAAM,WAAW,EAAE,UAAU,MAAM,SAAS;EAChD,IAAI,IAAI;EACR,MAAM,aAAa,WAAW;EAC9B,MAAM;EACN,OAAO,IAAI;EACX,cAAc;EACd,qBAAqB;EAErB,iBAAiB,QAAQ;EACzB,iBAAiB,IAAI;EACrB,yBACE,IAAI,gBAAgB,OAAO,KAAA,IAAY,SAAS,IAAI,cAAc,IAAI,WAAW;EACnF,UAAU,IAAI;EACd,WAAW,UAAyC;GAClD,IAAI,MAAM,MAAM,cAAc,OAAO,MAAM,WAAW;EACxD;EACA,YAAY,UAA2C;GACrD,IAAI,QAAQ,MAAM,WAAW;EAC/B;EACA,UAAU,UAAwC;GAChD,IAAI,QAAQ,MAAM,WAAW;EAC/B;EACA,SAAS,UAAwC;GAC/C,IAAI,SAAS,MAAM,WAAW;EAChC;EACA,UAAU,UAAwC;GAChD,IAAI,WAAW,MAAM,WAAW;EAClC;EACA,gBAAgB,UAA0C;GACxD,IAAI,iBAAiB,MAAM,WAAW;EACxC;EACA,aAAa,SAAS,QAAQ,UAAU;EACxC,gBAAgB,SAAS,MAAM,OAAO;EACtC,iBAAiB,SAAS,IAAI,UAAU,IAAI;EAC5C,cAAc,SAAS,IAAI,KAAK;EAChC,iBAAiB,SAAS,IAAI,QAAQ;CACxC;CAEA,OAAO,UAA8D;EACnE,gBAAgB;EAChB;EACA;EACA;EACA;EACA,UAAU,KAAA;EACV,OAAO;EACP;EACA,KAAK;CACP,CAAC;AACH;AAEA,cAAc,cAAc"}
1
+ {"version":3,"file":"combobox-input.mjs","names":[],"sources":["../../src/combobox/combobox-input.tsx"],"sourcesContent":["\"use client\";\nimport { isValidElement, useCallback } from \"react\";\nimport type {\n ChangeEvent,\n ComponentPropsWithRef,\n CSSProperties,\n FocusEvent,\n KeyboardEvent,\n MouseEvent,\n PointerEvent,\n} from \"react\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { registerTrigger } from \"../internal/overlay/trigger-ref.js\";\nimport { useElementCheck } from \"../internal/use-element-check.js\";\nimport { useFieldControl } from \"../internal/form/use-field-control.js\";\nimport { useMergedRefs } from \"../internal/use-merged-refs.js\";\nimport { useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport { optionId, useComboboxContext } from \"./combobox-context.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/** State of `Combobox.Input`, passed to the function forms of `className`, `style` and `render`. */\nexport interface ComboboxInputState {\n /** Optimistic selection; always `null` with `multiple` (read `values`). */\n readonly value: string | null;\n /** Optimistic selection as a list: pick order with `multiple`, `[value]` or `[]` otherwise. */\n readonly values: readonly string[];\n /** The urgent text. */\n readonly inputValue: string;\n /** Optimistic open state. */\n readonly open: boolean;\n /** The Root is pending (a selection or an open in flight). */\n readonly pending: boolean;\n /** The results shown are for an older text. */\n readonly stale: boolean;\n /** The Root's `disabled` (or the Field's). */\n readonly disabled: boolean;\n}\n\n/**\n * Props of `Combobox.Input`.\n *\n * @see https://ui.funstack.work/components/combobox\n */\nexport interface ComboboxInputProps extends Omit<\n ComponentPropsWithRef<\"input\">,\n | \"value\"\n | \"defaultValue\"\n | \"onChange\"\n | \"onInput\"\n | \"onKeyDown\"\n | \"onFocus\"\n | \"onBlur\"\n | \"onClick\"\n | \"onPointerDown\"\n | \"role\"\n | \"aria-autocomplete\"\n | \"aria-expanded\"\n | \"aria-controls\"\n | \"aria-activedescendant\"\n | \"autoComplete\"\n | \"disabled\"\n | \"className\"\n | \"style\"\n | \"children\"\n> {\n /**\n * Native `required`: empty text is `valueMissing`. With `multiple` it means \"at least one\n * value\": native `required` is rendered only while the selection is empty, and\n * `aria-required=\"true\"` always.\n */\n required?: boolean;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, ComboboxInputState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, ComboboxInputState>;\n /** Must render an `<input>` of type `text` or `search`. */\n render?: RenderProp<ComponentPropsWithRef<\"input\">, ComboboxInputState>;\n}\n\n/**\n * The text field: `<input role=\"combobox\" aria-autocomplete=\"list\" aria-expanded aria-controls\n * aria-activedescendant autocomplete=\"off\">`. DOM focus stays here while the active option moves\n * virtually (design 7.1). Its text is the Root's urgent `inputValue`; typing opens the listbox.\n *\n * Owned keys (conventions 1.2): `id`, `type`, `role`, `value`, `autoComplete`,\n * `aria-autocomplete`, `aria-expanded`, `aria-controls` (token-merged), `aria-activedescendant`,\n * `disabled`, `onChange`, `onKeyDown`, `onFocus` and `onBlur` (focus arriving starts the press\n * watch that decides a focus loss), `onClick`, `onPointerDown` (a primary-button press while the\n * listbox is shown captures the pointer to the Popup, so it is no light dismiss), `data-open`,\n * `data-pending`, `data-selected`, `data-stale`, `data-disabled`; inside a `Field.Root` (whose\n * control id it takes) also `required` (own or the Field's), `aria-describedby` (token-merged),\n * `aria-invalid` and `data-invalid`; with `multiple`, `required` (only while nothing is selected)\n * and `aria-required`. `onFocusCapture` passes through.\n *\n * @see https://ui.funstack.work/components/combobox\n */\nexport function ComboboxInput({ className, style, render, ...rest }: ComboboxInputProps) {\n const ctx = useComboboxContext(\"Combobox.Input\");\n const { popover, ids, inputRef } = ctx;\n const { triggerRef } = popover;\n\n const state: ComboboxInputState = {\n value: ctx.value,\n values: ctx.values,\n inputValue: ctx.inputValue,\n open: popover.optimistic,\n pending: ctx.pending,\n stale: ctx.stale,\n disabled: ctx.disabled,\n };\n\n const checkElement = useElementCheck(\n isDev &&\n ((element) => {\n const type = element.tagName === \"INPUT\" ? (element as HTMLInputElement).type : \"\";\n return type !== \"text\" && type !== \"search\"\n ? `Combobox.Input: rendered <${element.tagName.toLowerCase()}` +\n `${type === \"\" ? \"\" : ` type=\"${type}\"`}>. Render an <input> of type \"text\" or ` +\n '\"search\": `role=\"combobox\"`, `aria-activedescendant` and the caret keys depend on it.'\n : null;\n }),\n );\n const ref = useCallback(\n (element: HTMLElement) => {\n checkElement?.(element);\n inputRef.current = element as HTMLInputElement;\n // The popover's \"trigger\" is the input: `showPopover({ source: input })` anchors the\n // listbox to it and stacks a nested listbox under its popover (design 5.1). It does not\n // exempt presses on the input from light dismiss; `onPointerDown` does that.\n const unregister = registerTrigger(triggerRef, element, \"Combobox.Input\");\n return () => {\n if (inputRef.current === element) inputRef.current = null;\n unregister();\n };\n },\n [checkElement, inputRef, triggerRef],\n );\n\n // Inside a Field.Root (design/components/field-form.md 7.2) the Input is the Field's control:\n // the Root already took the Field's id for it; `required` and the ARIA wiring land here.\n const field = useFieldControl({\n labelable: true,\n required: rest.required,\n disabled: ctx.disabled,\n id: rest.id,\n component: \"Combobox.Input\",\n });\n const fieldRef = field.ref;\n const mergedRef = useMergedRefs<HTMLElement>(ref, fieldRef);\n\n const searchType = isValidElement<{ type?: unknown }>(render) && render.props.type === \"search\";\n\n // `multiple` (design 15.8): `required` means \"at least one value\", a computed native attribute\n // (conventions 3.6) that follows the optimistic selection; `aria-required` says it throughout.\n const required = field.inField ? field.required : rest.required === true;\n const requiredProps = ctx.multiple\n ? { required: required && ctx.values.length === 0, \"aria-required\": required || undefined }\n : field.inField && { required: field.required };\n\n const libraryProps: ComponentPropsWithRef<\"input\"> & DataAttributes = {\n ...field.attributes,\n ...requiredProps,\n id: ids.input,\n type: searchType ? \"search\" : \"text\",\n role: \"combobox\",\n value: ctx.inputValue,\n autoComplete: \"off\",\n \"aria-autocomplete\": \"list\",\n // Shown (the listbox is in the top layer); `data-open` is the optimistic one.\n \"aria-expanded\": popover.shown,\n \"aria-controls\": ids.list,\n \"aria-activedescendant\":\n ctx.activeValue === null ? undefined : optionId(ids.optionPrefix, ctx.activeValue),\n disabled: ctx.disabled,\n onChange: (event: ChangeEvent<HTMLInputElement>) => {\n ctx.typed(event.currentTarget.value, event.nativeEvent);\n },\n onKeyDown: (event: KeyboardEvent<HTMLInputElement>) => {\n ctx.keyDown(event.nativeEvent);\n },\n onFocus: (event: FocusEvent<HTMLInputElement>) => {\n ctx.focusIn(event.nativeEvent);\n },\n onBlur: (event: FocusEvent<HTMLInputElement>) => {\n ctx.focusOut(event.nativeEvent);\n },\n onClick: (event: MouseEvent<HTMLInputElement>) => {\n ctx.inputClick(event.nativeEvent);\n },\n onPointerDown: (event: PointerEvent<HTMLInputElement>) => {\n ctx.inputPointerDown(event.nativeEvent);\n },\n \"data-open\": dataAttr(popover.optimistic),\n \"data-pending\": dataAttr(state.pending),\n \"data-selected\": dataAttr(ctx.values.length > 0),\n \"data-stale\": dataAttr(ctx.stale),\n \"data-disabled\": dataAttr(ctx.disabled),\n };\n\n return useRender<ComponentPropsWithRef<\"input\">, ComboboxInputState>({\n defaultElement: \"input\",\n render,\n state,\n className,\n style,\n children: undefined,\n props: rest,\n libraryProps,\n ref: mergedRef,\n });\n}\n\nComboboxInput.displayName = \"ComboboxInput\";\n"],"mappings":";;;;;;;;;;;AAqBA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;;;;;;;;;;;;;;;;;AA8EvC,SAAgB,cAAc,EAAE,WAAW,OAAO,QAAQ,GAAG,QAA4B;CACvF,MAAM,MAAM,mBAAmB,gBAAgB;CAC/C,MAAM,EAAE,SAAS,KAAK,aAAa;CACnC,MAAM,EAAE,eAAe;CAEvB,MAAM,QAA4B;EAChC,OAAO,IAAI;EACX,QAAQ,IAAI;EACZ,YAAY,IAAI;EAChB,MAAM,QAAQ;EACd,SAAS,IAAI;EACb,OAAO,IAAI;EACX,UAAU,IAAI;CAChB;CAEA,MAAM,eAAe,gBACnB,WACI,YAAY;EACZ,MAAM,OAAO,QAAQ,YAAY,UAAW,QAA6B,OAAO;EAChF,OAAO,SAAS,UAAU,SAAS,WAC/B,6BAA6B,QAAQ,QAAQ,YAAY,IACpD,SAAS,KAAK,KAAK,UAAU,KAAK,GAAG,oIAE1C;CACN,EACJ;CACA,MAAM,MAAM,aACT,YAAyB;EACxB,eAAe,OAAO;EACtB,SAAS,UAAU;EAInB,MAAM,aAAa,gBAAgB,YAAY,SAAS,gBAAgB;EACxE,aAAa;GACX,IAAI,SAAS,YAAY,SAAS,SAAS,UAAU;GACrD,WAAW;EACb;CACF,GACA;EAAC;EAAc;EAAU;CAAU,CACrC;CAIA,MAAM,QAAQ,gBAAgB;EAC5B,WAAW;EACX,UAAU,KAAK;EACf,UAAU,IAAI;EACd,IAAI,KAAK;EACT,WAAW;CACb,CAAC;CACD,MAAM,WAAW,MAAM;CACvB,MAAM,YAAY,cAA2B,KAAK,QAAQ;CAE1D,MAAM,aAAa,eAAmC,MAAM,KAAK,OAAO,MAAM,SAAS;CAIvF,MAAM,WAAW,MAAM,UAAU,MAAM,WAAW,KAAK,aAAa;CACpE,MAAM,gBAAgB,IAAI,WACtB;EAAE,UAAU,YAAY,IAAI,OAAO,WAAW;EAAG,iBAAiB,YAAY,KAAA;CAAU,IACxF,MAAM,WAAW,EAAE,UAAU,MAAM,SAAS;CAEhD,MAAM,eAAgE;EACpE,GAAG,MAAM;EACT,GAAG;EACH,IAAI,IAAI;EACR,MAAM,aAAa,WAAW;EAC9B,MAAM;EACN,OAAO,IAAI;EACX,cAAc;EACd,qBAAqB;EAErB,iBAAiB,QAAQ;EACzB,iBAAiB,IAAI;EACrB,yBACE,IAAI,gBAAgB,OAAO,KAAA,IAAY,SAAS,IAAI,cAAc,IAAI,WAAW;EACnF,UAAU,IAAI;EACd,WAAW,UAAyC;GAClD,IAAI,MAAM,MAAM,cAAc,OAAO,MAAM,WAAW;EACxD;EACA,YAAY,UAA2C;GACrD,IAAI,QAAQ,MAAM,WAAW;EAC/B;EACA,UAAU,UAAwC;GAChD,IAAI,QAAQ,MAAM,WAAW;EAC/B;EACA,SAAS,UAAwC;GAC/C,IAAI,SAAS,MAAM,WAAW;EAChC;EACA,UAAU,UAAwC;GAChD,IAAI,WAAW,MAAM,WAAW;EAClC;EACA,gBAAgB,UAA0C;GACxD,IAAI,iBAAiB,MAAM,WAAW;EACxC;EACA,aAAa,SAAS,QAAQ,UAAU;EACxC,gBAAgB,SAAS,MAAM,OAAO;EACtC,iBAAiB,SAAS,IAAI,OAAO,SAAS,CAAC;EAC/C,cAAc,SAAS,IAAI,KAAK;EAChC,iBAAiB,SAAS,IAAI,QAAQ;CACxC;CAEA,OAAO,UAA8D;EACnE,gBAAgB;EAChB;EACA;EACA;EACA;EACA,UAAU,KAAA;EACV,OAAO;EACP;EACA,KAAK;CACP,CAAC;AACH;AAEA,cAAc,cAAc"}
@@ -2,12 +2,23 @@
2
2
  import { isPopoverOpen } from "../internal/overlay/popover-open.mjs";
3
3
  import { flushSync } from "react-dom";
4
4
  //#region src/combobox/combobox-keyboard.ts
5
+ /** The caret is at the start of the input with nothing selected. */
6
+ function caretAtStart(target) {
7
+ if (!(target instanceof HTMLInputElement)) return false;
8
+ return target.selectionStart === 0 && target.selectionEnd === 0;
9
+ }
10
+ /** ArrowLeft, or ArrowRight when the input's computed direction is `rtl` (design 15.6). */
11
+ function isInlineStartArrow(event) {
12
+ const target = event.target;
13
+ const rtl = target instanceof Element && target.ownerDocument.defaultView?.getComputedStyle(target).direction === "rtl";
14
+ return event.key === (rtl ? "ArrowRight" : "ArrowLeft");
15
+ }
5
16
  /**
6
17
  * The keyboard model of the Combobox Input (design/components/combobox.md 8), the counterpart of
7
18
  * `menu/use-menu-keyboard.ts`. A plain factory, not a hook (it calls none): the Root calls it on
8
19
  * every render. Returns the Input's `keydown` handler, which tells whether it handled the key.
9
20
  */
10
- function createComboboxKeyDown({ disabled, loop, allowCustomValue, popover, options, active, accept, commitText }) {
21
+ function createComboboxKeyDown({ disabled, loop, allowCustomValue, popover, options, active, accept, commitText, multiple }) {
11
22
  const { registry, orderedOptions } = options;
12
23
  const { activeRef, setActive, pendingEdgeRef } = active;
13
24
  const move = (direction) => {
@@ -45,7 +56,8 @@ function createComboboxKeyDown({ disabled, loop, allowCustomValue, popover, opti
45
56
  case "ArrowUp":
46
57
  event.preventDefault();
47
58
  if (event.altKey) {
48
- if (isOpen) {
59
+ if (isOpen && multiple !== void 0) popover.requestClose(event, "activate");
60
+ else if (isOpen) {
49
61
  const current = activeEnabled();
50
62
  if (current !== null) accept(current, event);
51
63
  else popover.requestClose(event, "activate");
@@ -56,6 +68,27 @@ function createComboboxKeyDown({ disabled, loop, allowCustomValue, popover, opti
56
68
  } else move(-1);
57
69
  return true;
58
70
  case "Enter":
71
+ if (multiple !== void 0) {
72
+ if (isOpen) {
73
+ event.preventDefault();
74
+ const current = activeEnabled();
75
+ if (current !== null) accept(current, event);
76
+ else if (allowCustomValue && multiple.textRef.current !== "") multiple.addText(event);
77
+ return true;
78
+ }
79
+ if (multiple.textRef.current === "") return false;
80
+ if (popover.intended() && !popover.committed) {
81
+ event.preventDefault();
82
+ return true;
83
+ }
84
+ if (allowCustomValue) {
85
+ event.preventDefault();
86
+ multiple.addText(event);
87
+ return true;
88
+ }
89
+ flushSync(() => multiple.clearText(event));
90
+ return false;
91
+ }
59
92
  if (isOpen) {
60
93
  event.preventDefault();
61
94
  const current = activeEnabled();
@@ -65,10 +98,23 @@ function createComboboxKeyDown({ disabled, loop, allowCustomValue, popover, opti
65
98
  }
66
99
  if (allowCustomValue) flushSync(() => commitText(event, false));
67
100
  return false;
68
- case "Home":
69
- case "End":
101
+ case "Backspace":
102
+ if (multiple !== void 0 && !event.repeat && !event.altKey && multiple.textRef.current === "" && multiple.hasChips()) {
103
+ multiple.removeLast(event);
104
+ return true;
105
+ }
106
+ return false;
70
107
  case "ArrowLeft":
71
108
  case "ArrowRight":
109
+ if (multiple !== void 0 && !event.altKey && !event.shiftKey && isInlineStartArrow(event) && caretAtStart(event.target) && multiple.hasChips() && multiple.focusLastChip()) {
110
+ event.preventDefault();
111
+ if (activeRef.current !== null) setActive(null);
112
+ return true;
113
+ }
114
+ if (activeRef.current !== null) setActive(null);
115
+ return false;
116
+ case "Home":
117
+ case "End":
72
118
  if (activeRef.current !== null) setActive(null);
73
119
  return false;
74
120
  default: return false;