@pzerelles/headlessui-svelte 2.1.2-next.2 → 2.1.2-next.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 (168) hide show
  1. package/dist/button/Button.svelte.d.ts +1 -1
  2. package/dist/checkbox/Checkbox.svelte +4 -4
  3. package/dist/checkbox/Checkbox.svelte.d.ts +5 -7
  4. package/dist/close-button/CloseButton.svelte.d.ts +2 -2
  5. package/dist/data-interactive/DataInteractive.svelte.d.ts +1 -1
  6. package/dist/description/Description.svelte.d.ts +1 -1
  7. package/dist/description/context.svelte.js +1 -1
  8. package/dist/dialog/Dialog.svelte.d.ts +1 -1
  9. package/dist/dialog/DialogBackdrop.svelte.d.ts +1 -1
  10. package/dist/dialog/DialogPanel.svelte +0 -1
  11. package/dist/dialog/DialogPanel.svelte.d.ts +1 -1
  12. package/dist/dialog/DialogTitle.svelte.d.ts +1 -1
  13. package/dist/dialog/InternalDialog.svelte.d.ts +1 -1
  14. package/dist/dialog/context.svelte.js +1 -1
  15. package/dist/field/Field.svelte +21 -3
  16. package/dist/field/Field.svelte.d.ts +1 -1
  17. package/dist/fieldset/Fieldset.svelte.d.ts +1 -1
  18. package/dist/focus-trap/FocusTrap.svelte +7 -14
  19. package/dist/focus-trap/FocusTrap.svelte.d.ts +3 -15
  20. package/dist/focus-trap/FocusTrapFeatures.d.ts +14 -0
  21. package/dist/focus-trap/FocusTrapFeatures.js +15 -0
  22. package/dist/hooks/use-controllable.svelte.js +2 -1
  23. package/dist/hooks/use-did-element-move.svelte.js +5 -10
  24. package/dist/hooks/use-event-listener.svelte.d.ts +1 -1
  25. package/dist/hooks/use-event-listener.svelte.js +3 -1
  26. package/dist/hooks/use-root-containers.svelte.d.ts +2 -2
  27. package/dist/hooks/use-root-containers.svelte.js +5 -5
  28. package/dist/hooks/use-tab-direction.svelte.js +1 -1
  29. package/dist/index.d.ts +3 -0
  30. package/dist/index.js +3 -0
  31. package/dist/input/Input.svelte +2 -2
  32. package/dist/input/Input.svelte.d.ts +5 -7
  33. package/dist/internal/FloatingProvider.svelte +12 -0
  34. package/dist/internal/{HoistFormFields.svelte.d.ts → FloatingProvider.svelte.d.ts} +5 -4
  35. package/dist/internal/FormFields.svelte +22 -19
  36. package/dist/internal/FormFieldsProvider.svelte +13 -0
  37. package/dist/internal/FormFieldsProvider.svelte.d.ts +21 -0
  38. package/dist/internal/Hidden.svelte +18 -8
  39. package/dist/internal/Hidden.svelte.d.ts +3 -6
  40. package/dist/internal/HiddenFeatures.d.ts +5 -0
  41. package/dist/internal/HiddenFeatures.js +9 -0
  42. package/dist/internal/floating-provider.svelte.d.ts +3 -0
  43. package/dist/internal/floating-provider.svelte.js +206 -0
  44. package/dist/internal/floating.svelte.d.ts +48 -23
  45. package/dist/internal/floating.svelte.js +79 -260
  46. package/dist/internal/form-fields.svelte.d.ts +10 -0
  47. package/dist/internal/form-fields.svelte.js +23 -0
  48. package/dist/label/Label.svelte +5 -4
  49. package/dist/label/Label.svelte.d.ts +1 -1
  50. package/dist/label/context.svelte.js +1 -1
  51. package/dist/legend/Legend.svelte +2 -2
  52. package/dist/legend/Legend.svelte.d.ts +18 -30
  53. package/dist/listbox/Listbox.svelte +42 -66
  54. package/dist/listbox/Listbox.svelte.d.ts +6 -65
  55. package/dist/listbox/ListboxButton.svelte +10 -10
  56. package/dist/listbox/ListboxButton.svelte.d.ts +5 -7
  57. package/dist/listbox/ListboxOption.svelte +10 -6
  58. package/dist/listbox/ListboxOption.svelte.d.ts +1 -1
  59. package/dist/listbox/ListboxOptions.svelte +108 -54
  60. package/dist/listbox/ListboxOptions.svelte.d.ts +1 -1
  61. package/dist/listbox/ListboxSelectedOption.svelte +2 -4
  62. package/dist/listbox/ListboxSelectedOption.svelte.d.ts +6 -6
  63. package/dist/listbox/context.svelte.d.ts +76 -0
  64. package/dist/listbox/context.svelte.js +36 -0
  65. package/dist/menu/Menu.svelte +5 -177
  66. package/dist/menu/Menu.svelte.d.ts +1 -1
  67. package/dist/menu/MenuButton.svelte +4 -2
  68. package/dist/menu/MenuButton.svelte.d.ts +1 -1
  69. package/dist/menu/MenuHeading.svelte.d.ts +1 -1
  70. package/dist/menu/MenuItem.svelte.d.ts +6 -5
  71. package/dist/menu/MenuItems.svelte +15 -11
  72. package/dist/menu/MenuItems.svelte.d.ts +1 -1
  73. package/dist/menu/MenuSection.svelte.d.ts +1 -1
  74. package/dist/menu/MenuSeparator.svelte.d.ts +1 -1
  75. package/dist/menu/context.svelte.d.ts +30 -1
  76. package/dist/menu/context.svelte.js +208 -0
  77. package/dist/popover/Popover.svelte +161 -0
  78. package/dist/popover/Popover.svelte.d.ts +41 -0
  79. package/dist/popover/PopoverBackdrop.svelte +56 -0
  80. package/dist/popover/PopoverBackdrop.svelte.d.ts +45 -0
  81. package/dist/popover/PopoverButton.svelte +246 -0
  82. package/dist/popover/PopoverButton.svelte.d.ts +46 -0
  83. package/dist/popover/PopoverGroup.svelte +43 -0
  84. package/dist/popover/PopoverGroup.svelte.d.ts +33 -0
  85. package/dist/popover/PopoverPanel.svelte +274 -0
  86. package/dist/popover/PopoverPanel.svelte.d.ts +53 -0
  87. package/dist/popover/context.svelte.d.ts +51 -0
  88. package/dist/popover/context.svelte.js +108 -0
  89. package/dist/popover/index.d.ts +5 -0
  90. package/dist/popover/index.js +5 -0
  91. package/dist/portal/InternalPortal.svelte.d.ts +1 -1
  92. package/dist/portal/PortalGroup.svelte.d.ts +1 -1
  93. package/dist/select/Select.svelte +74 -0
  94. package/dist/select/Select.svelte.d.ts +48 -0
  95. package/dist/select/index.d.ts +1 -0
  96. package/dist/select/index.js +1 -0
  97. package/dist/switch/Switch.svelte +30 -20
  98. package/dist/switch/Switch.svelte.d.ts +5 -5
  99. package/dist/switch/SwitchGroup.svelte.d.ts +1 -1
  100. package/dist/tabs/Tab.svelte.d.ts +1 -1
  101. package/dist/tabs/TabGroup.svelte.d.ts +2 -2
  102. package/dist/tabs/TabList.svelte.d.ts +1 -1
  103. package/dist/tabs/TabPanel.svelte.d.ts +1 -1
  104. package/dist/tabs/TabPanels.svelte.d.ts +1 -1
  105. package/dist/textarea/Textarea.svelte +67 -0
  106. package/dist/textarea/Textarea.svelte.d.ts +50 -0
  107. package/dist/textarea/index.d.ts +1 -0
  108. package/dist/textarea/index.js +1 -0
  109. package/dist/transition/InternalTransitionChild.svelte.d.ts +1 -1
  110. package/dist/transition/Transition.svelte.d.ts +1 -1
  111. package/dist/transition/TransitionChild.svelte.d.ts +1 -1
  112. package/dist/transition/context.svelte.js +2 -2
  113. package/dist/utils/ElementOrComponent.svelte +2 -2
  114. package/dist/utils/ElementOrComponent.svelte.d.ts +2 -2
  115. package/dist/utils/Generic.svelte +0 -1
  116. package/dist/utils/Generic.svelte.d.ts +1 -2
  117. package/dist/utils/alternative-types.d.ts +1 -2
  118. package/dist/utils/floating-ui/svelte/components/FloatingNode.svelte +17 -0
  119. package/dist/utils/floating-ui/svelte/components/FloatingNode.svelte.d.ts +23 -0
  120. package/dist/utils/floating-ui/svelte/components/FloatingTree.svelte +50 -0
  121. package/dist/utils/floating-ui/svelte/components/FloatingTree.svelte.d.ts +41 -0
  122. package/dist/utils/floating-ui/svelte/hooks/useFloating.svelte.d.ts +6 -0
  123. package/dist/utils/floating-ui/svelte/hooks/useFloating.svelte.js +158 -0
  124. package/dist/utils/floating-ui/svelte/hooks/useFloatingRootContext.svelte.d.ts +11 -0
  125. package/dist/utils/floating-ui/svelte/hooks/useFloatingRootContext.svelte.js +53 -0
  126. package/dist/utils/floating-ui/svelte/hooks/useId.svelte.d.ts +9 -0
  127. package/dist/utils/floating-ui/svelte/hooks/useId.svelte.js +28 -0
  128. package/dist/utils/floating-ui/svelte/hooks/useInteractions.svelte.d.ts +23 -0
  129. package/dist/utils/floating-ui/svelte/hooks/useInteractions.svelte.js +72 -0
  130. package/dist/utils/floating-ui/svelte/index.d.ts +5 -0
  131. package/dist/utils/floating-ui/svelte/index.js +5 -0
  132. package/dist/utils/floating-ui/svelte/inner.svelte.d.ts +83 -0
  133. package/dist/utils/floating-ui/svelte/inner.svelte.js +178 -0
  134. package/dist/utils/floating-ui/svelte/types.d.ts +114 -0
  135. package/dist/utils/floating-ui/svelte/types.js +1 -0
  136. package/dist/utils/floating-ui/svelte/utils/createPubSub.d.ts +5 -0
  137. package/dist/utils/floating-ui/svelte/utils/createPubSub.js +14 -0
  138. package/dist/utils/floating-ui/svelte/utils/getFloatingFocusElement.d.ts +2 -0
  139. package/dist/utils/floating-ui/svelte/utils/getFloatingFocusElement.js +13 -0
  140. package/dist/utils/floating-ui/svelte/utils/log.d.ts +2 -0
  141. package/dist/utils/floating-ui/svelte/utils/log.js +19 -0
  142. package/dist/utils/floating-ui/svelte/utils.d.ts +19 -0
  143. package/dist/utils/floating-ui/svelte/utils.js +136 -0
  144. package/dist/utils/floating-ui/svelte-dom/arrow.d.ts +22 -0
  145. package/dist/utils/floating-ui/svelte-dom/arrow.js +29 -0
  146. package/dist/utils/floating-ui/svelte-dom/index.d.ts +2 -0
  147. package/dist/utils/floating-ui/svelte-dom/index.js +2 -0
  148. package/dist/utils/floating-ui/svelte-dom/types.d.ts +80 -0
  149. package/dist/utils/floating-ui/svelte-dom/types.js +3 -0
  150. package/dist/utils/floating-ui/svelte-dom/useFloating.svelte.d.ts +6 -0
  151. package/dist/utils/floating-ui/svelte-dom/useFloating.svelte.js +182 -0
  152. package/dist/utils/floating-ui/svelte-dom/utils/deepEqual.d.ts +1 -0
  153. package/dist/utils/floating-ui/svelte-dom/utils/deepEqual.js +50 -0
  154. package/dist/utils/floating-ui/svelte-dom/utils/getDPR.d.ts +1 -0
  155. package/dist/utils/floating-ui/svelte-dom/utils/getDPR.js +7 -0
  156. package/dist/utils/floating-ui/svelte-dom/utils/roundByDPR.d.ts +1 -0
  157. package/dist/utils/floating-ui/svelte-dom/utils/roundByDPR.js +5 -0
  158. package/dist/utils/floating-ui/svelte-dom/utils/useLatestRef.d.ts +4 -0
  159. package/dist/utils/floating-ui/svelte-dom/utils/useLatestRef.js +7 -0
  160. package/dist/utils/id.d.ts +1 -1
  161. package/dist/utils/id.js +1 -1
  162. package/dist/utils/style.d.ts +2 -0
  163. package/dist/utils/style.js +6 -0
  164. package/dist/utils/types.d.ts +1 -2
  165. package/package.json +25 -24
  166. package/dist/internal/HoistFormFields.svelte +0 -11
  167. package/dist/internal/id.d.ts +0 -8
  168. package/dist/internal/id.js +0 -11
@@ -4,51 +4,20 @@ import { useDisabled } from "../hooks/use-disabled.js";
4
4
  import { calculateActiveIndex, Focus } from "../utils/calculate-active-index.js";
5
5
  import { FocusableMode, isFocusableElement, sortByDomNode } from "../utils/focus-management.js";
6
6
  import { match } from "../utils/match.js";
7
- import { useRef } from "../utils/ref.svelte.js";
8
- import { getContext, setContext } from "svelte";
7
+ import { setContext } from "svelte";
8
+ import { ActivationTrigger, ListboxStates, ValueMode } from "./context.svelte.js";
9
9
  let DEFAULT_LISTBOX_TAG = "svelte:fragment";
10
- export var ListboxStates = /* @__PURE__ */ ((ListboxStates2) => {
11
- ListboxStates2[ListboxStates2["Open"] = 0] = "Open";
12
- ListboxStates2[ListboxStates2["Closed"] = 1] = "Closed";
13
- return ListboxStates2;
14
- })(ListboxStates || {});
15
- export var ValueMode = /* @__PURE__ */ ((ValueMode2) => {
16
- ValueMode2[ValueMode2["Single"] = 0] = "Single";
17
- ValueMode2[ValueMode2["Multi"] = 1] = "Multi";
18
- return ValueMode2;
19
- })(ValueMode || {});
20
- export var ActivationTrigger = /* @__PURE__ */ ((ActivationTrigger2) => {
21
- ActivationTrigger2[ActivationTrigger2["Pointer"] = 0] = "Pointer";
22
- ActivationTrigger2[ActivationTrigger2["Other"] = 1] = "Other";
23
- return ActivationTrigger2;
24
- })(ActivationTrigger || {});
25
- export function useActions(component) {
26
- const context = getContext("ListboxActionsContext");
27
- if (!context) {
28
- let err = new Error(`<${component} /> is missing a parent <Listbox /> component.`);
29
- if (Error.captureStackTrace) Error.captureStackTrace(err, useActions);
30
- throw err;
31
- }
32
- return context;
33
- }
34
- export function useData(component) {
35
- const context = getContext("ListboxData");
36
- if (context === null) {
37
- let err = new Error(`<${component} /> is missing a parent <Listbox /> component.`);
38
- if (Error.captureStackTrace) Error.captureStackTrace(err, useData);
39
- throw err;
40
- }
41
- return context;
42
- }
10
+ export * from "./context.svelte.js";
43
11
  </script>
44
12
 
45
13
  <script lang="ts" generics="TType, TActualType, TTag extends ElementType = typeof DEFAULT_LISTBOX_TAG">import { disposables } from "../utils/disposables.js";
46
14
  import FormFields from "../internal/FormFields.svelte";
47
- import { createFloatingContext } from "../internal/floating.svelte.js";
15
+ import { useFloatingProvider } from "../internal/floating.svelte.js";
48
16
  import { createOpenClosedContext, State } from "../internal/open-closed.js";
49
17
  import { useLabels } from "../label/context.svelte.js";
50
18
  import { useOutsideClick } from "../hooks/use-outside-click.svelte.js";
51
19
  import ElementOrComponent from "../utils/ElementOrComponent.svelte";
20
+ import { SvelteMap } from "svelte/reactivity";
52
21
  function adjustOrderedState(state, adjustment = (i) => i) {
53
22
  let currentActiveOption = state.activeOptionIndex !== null ? state.options[state.activeOptionIndex] : null;
54
23
  let sortedOptions = sortByDomNode(
@@ -202,11 +171,11 @@ const stateReducer = (initialState) => {
202
171
  _state2.searchQuery = "";
203
172
  return _state2;
204
173
  },
205
- registerOption(action) {
206
- let option = { id: action.id, dataRef: action.dataRef };
174
+ registerOption(id, dataRef) {
175
+ let option = { id, dataRef };
207
176
  let adjustedState = adjustOrderedState(_state2, (options) => [...options, option]);
208
177
  if (_state2.activeOptionIndex === null) {
209
- if (isSelected(action.dataRef.current.value)) {
178
+ if (isSelected(dataRef.current.value)) {
210
179
  adjustedState.activeOptionIndex = adjustedState.options.indexOf(option);
211
180
  }
212
181
  }
@@ -214,9 +183,9 @@ const stateReducer = (initialState) => {
214
183
  _state2.activeOptionIndex = adjustedState.activeOptionIndex;
215
184
  return _state2;
216
185
  },
217
- unregisterOption(action) {
186
+ unregisterOption(id) {
218
187
  let adjustedState = adjustOrderedState(_state2, (options) => {
219
- let idx = options.findIndex((a) => a.id === action.id);
188
+ let idx = options.findIndex((a) => a.id === id);
220
189
  if (idx !== -1) options.splice(idx, 1);
221
190
  return options;
222
191
  });
@@ -227,14 +196,9 @@ const stateReducer = (initialState) => {
227
196
  }
228
197
  };
229
198
  };
230
- const listboxActionsContext = null;
231
- setContext("ListboxActionsContext", listboxActionsContext);
232
- const listboxDataContext = null;
233
- setContext("ListboxDataContext", listboxDataContext);
234
199
  let {
235
200
  ref = $bindable(),
236
- as,
237
- value: controlledValue,
201
+ value: controlledValue = $bindable(),
238
202
  defaultValue,
239
203
  form,
240
204
  name,
@@ -244,6 +208,7 @@ let {
244
208
  disabled: ownDisabled = false,
245
209
  horizontal = false,
246
210
  multiple = false,
211
+ closeOnSelect,
247
212
  __demoMode = false,
248
213
  ...theirProps
249
214
  } = $props();
@@ -254,6 +219,9 @@ const controllable = useControllable(
254
219
  {
255
220
  get controlledValue() {
256
221
  return controlledValue;
222
+ },
223
+ set controlledValue(value2) {
224
+ controlledValue = value2;
257
225
  }
258
226
  },
259
227
  controlledOnChange,
@@ -269,10 +237,10 @@ const _state = stateReducer({
269
237
  optionsVisible: false,
270
238
  __demoMode
271
239
  });
272
- const optionsPropsRef = useRef({ static: false, hold: false });
273
- const buttonRef = useRef(null);
274
- const optionsRef = useRef(null);
275
- const listRef = useRef(/* @__PURE__ */ new Map());
240
+ const optionsProps = $state({ static: false, hold: false });
241
+ let buttonElement = $state(null);
242
+ let optionsElement = $state(null);
243
+ const listElements = new SvelteMap();
276
244
  const compare = useByComparator(by);
277
245
  const isSelected = (compareValue) => match(data.mode, {
278
246
  [ValueMode.Multi]: () => {
@@ -316,36 +284,44 @@ const data = {
316
284
  get orientation() {
317
285
  return orientation;
318
286
  },
287
+ get closeOnSelect() {
288
+ return closeOnSelect;
289
+ },
319
290
  compare,
320
291
  isSelected,
321
- get optionsPropsRef() {
322
- return optionsPropsRef;
292
+ get optionsProps() {
293
+ return optionsProps;
294
+ },
295
+ get buttonElement() {
296
+ return buttonElement;
297
+ },
298
+ set buttonElement(value2) {
299
+ buttonElement = value2;
323
300
  },
324
- get buttonRef() {
325
- return buttonRef;
301
+ get optionsElement() {
302
+ return optionsElement;
326
303
  },
327
- get optionsRef() {
328
- return optionsRef;
304
+ set optionsElement(value2) {
305
+ optionsElement = value2;
329
306
  },
330
- get listRef() {
331
- return listRef;
307
+ get listElements() {
308
+ return listElements;
332
309
  }
333
310
  };
334
311
  setContext("ListboxDataContext", data);
335
- setContext("ListboxData", data);
336
312
  const outsideClickEnabled = $derived(data.listboxState === ListboxStates.Open);
337
313
  useOutsideClick({
338
314
  get enabled() {
339
315
  return outsideClickEnabled;
340
316
  },
341
317
  get containers() {
342
- return [data.buttonRef, data.optionsRef];
318
+ return [data.buttonElement, data.optionsElement];
343
319
  },
344
320
  cb: (event, target) => {
345
321
  _state.closeListbox();
346
322
  if (!isFocusableElement(target, FocusableMode.Loose)) {
347
323
  event.preventDefault();
348
- data.buttonRef.current?.focus();
324
+ data.buttonElement?.focus();
349
325
  }
350
326
  }
351
327
  });
@@ -377,8 +353,8 @@ const goToOption = (focus, id, trigger) => {
377
353
  });
378
354
  };
379
355
  const registerOption = (id, dataRef) => {
380
- _state.registerOption({ id, dataRef });
381
- return () => _state.unregisterOption({ id });
356
+ _state.registerOption(id, dataRef);
357
+ return () => _state.unregisterOption(id);
382
358
  };
383
359
  const onChange = (value2) => {
384
360
  return match(data.mode, {
@@ -408,7 +384,7 @@ setContext("ListboxActionsContext", {
408
384
  search: _state.search,
409
385
  clearSearch: _state.clearSearch
410
386
  });
411
- createFloatingContext();
387
+ useFloatingProvider();
412
388
  const openClosed = $derived(
413
389
  match(data.listboxState, {
414
390
  [ListboxStates.Open]: State.Open,
@@ -424,7 +400,7 @@ useLabels({
424
400
  inherit: true,
425
401
  props: {
426
402
  get htmlFor() {
427
- return data.buttonRef.current?.id;
403
+ return data.buttonElement?.id;
428
404
  }
429
405
  },
430
406
  slot: {
@@ -1,6 +1,4 @@
1
1
  import { type ByComparator } from "../hooks/use-by-comparator.js";
2
- import { Focus } from "../utils/calculate-active-index.js";
3
- import { type MutableRefObject } from "../utils/ref.svelte.js";
4
2
  import type { ElementType, Props } from "../utils/types.js";
5
3
  import { type Snippet } from "svelte";
6
4
  declare let DEFAULT_LISTBOX_TAG: string;
@@ -21,74 +19,16 @@ export type ListboxProps<TTag extends ElementType = typeof DEFAULT_LISTBOX_TAG,
21
19
  form?: string;
22
20
  name?: string;
23
21
  multiple?: boolean;
22
+ closeOnSelect?: boolean;
24
23
  __demoMode?: boolean;
25
24
  }>;
26
25
  export type ListboxChildren<T> = Snippet<[ListboxRenderPropArg<T>]>;
27
- export declare enum ListboxStates {
28
- Open = 0,
29
- Closed = 1
30
- }
31
- export declare enum ValueMode {
32
- Single = 0,
33
- Multi = 1
34
- }
35
- export declare enum ActivationTrigger {
36
- Pointer = 0,
37
- Other = 1
38
- }
39
- export type ListboxOptionDataRef<T> = MutableRefObject<{
40
- textValue?: string;
41
- disabled: boolean;
42
- value: T;
43
- domRef: MutableRefObject<HTMLElement | null>;
44
- }>;
45
- interface StateDefinition<T> {
46
- listboxState: ListboxStates;
47
- options: {
48
- id: string;
49
- dataRef: ListboxOptionDataRef<T>;
50
- }[];
51
- searchQuery: string;
52
- activeOptionIndex: number | null;
53
- activationTrigger: ActivationTrigger;
54
- __demoMode: boolean;
55
- }
56
- type ListboxActionsContext = {
57
- openListbox(): void;
58
- closeListbox(): void;
59
- registerOption(id: string, dataRef: ListboxOptionDataRef<unknown>): () => void;
60
- goToOption(focus: Focus.Specific, id: string, trigger?: ActivationTrigger): void;
61
- goToOption(focus: Focus, id?: string, trigger?: ActivationTrigger): void;
62
- selectOption(id: string): void;
63
- selectActiveOption(): void;
64
- onChange(value: unknown): void;
65
- search(query: string): void;
66
- clearSearch(): void;
67
- };
68
- export declare function useActions(component: string): ListboxActionsContext;
69
- export type ListboxDataContext = {
70
- value: unknown;
71
- disabled: boolean;
72
- invalid: boolean;
73
- mode: ValueMode;
74
- orientation: "horizontal" | "vertical";
75
- activeOptionIndex: number | null;
76
- compare(a: unknown, z: unknown): boolean;
77
- isSelected(value: unknown): boolean;
78
- optionsPropsRef: MutableRefObject<{
79
- static: boolean;
80
- hold: boolean;
81
- }>;
82
- listRef: MutableRefObject<Map<string, HTMLElement | null>>;
83
- buttonRef: MutableRefObject<HTMLElement | null>;
84
- optionsRef: MutableRefObject<HTMLElement | null>;
85
- } & Omit<StateDefinition<unknown>, "dataRef">;
86
- export declare function useData(component: string): ListboxDataContext;
26
+ export * from "./context.svelte.js";
87
27
  declare class __sveltets_Render<TType, TActualType, TTag extends ElementType = typeof DEFAULT_LISTBOX_TAG> {
88
28
  props(): {
89
29
  as?: TTag | undefined;
90
- } & (Exclude<keyof import("../utils/types.js").PropsOf<TTag>, "form" | ("as" | "children" | "refName" | "class") | "invalid" | "disabled" | "name" | "value" | "onchange" | "multiple" | "__demoMode" | "defaultValue" | "by" | "horizontal"> extends infer T extends keyof import("../utils/types.js").PropsOf<TTag> ? { [P in T]: import("../utils/types.js").PropsOf<TTag>[P]; } : never) & {
91
- children?: import("../utils/types.js").Children<ListboxRenderPropArg<TType>> | undefined;
30
+ } & (Exclude<keyof import("../utils/types.js").PropsOf<TTag>, "form" | ("as" | "children" | "refName" | "class") | "invalid" | "disabled" | "value" | "name" | "onchange" | "multiple" | "__demoMode" | "horizontal" | "defaultValue" | "by" | "closeOnSelect"> extends infer T extends keyof import("../utils/types.js").PropsOf<TTag> ? { [P in T]: import("../utils/types.js").PropsOf<TTag>[P]; } : never) & {
31
+ children?: Snippet<[ListboxRenderPropArg<TType>, Record<string, any>]> | undefined;
92
32
  ref?: HTMLElement;
93
33
  } & (true extends (import("../utils/types.js").PropsOf<TTag> extends infer T_1 ? T_1 extends import("../utils/types.js").PropsOf<TTag> ? T_1 extends never ? never : "class" extends infer T_2 ? T_2 extends "class" ? T_2 extends keyof T_1 ? true : never : never : never : never : never) ? {
94
34
  class?: import("../utils/types.js").PropsOf<TTag>["class"] | ((bag: ListboxRenderPropArg<TType>) => string) | undefined;
@@ -103,13 +43,14 @@ declare class __sveltets_Render<TType, TActualType, TTag extends ElementType = t
103
43
  form?: string;
104
44
  name?: string;
105
45
  multiple?: boolean;
46
+ closeOnSelect?: boolean;
106
47
  __demoMode?: boolean;
107
48
  };
108
49
  events(): {} & {
109
50
  [evt: string]: CustomEvent<any>;
110
51
  };
111
52
  slots(): {};
112
- bindings(): "ref";
53
+ bindings(): "ref" | "value";
113
54
  exports(): {};
114
55
  }
115
56
  interface $$IsomorphicComponent {
@@ -1,12 +1,12 @@
1
1
  <script lang="ts" module>import { useId } from "../hooks/use-id.js";
2
- import { getIdContext } from "../utils/id.js";
2
+ import { useProvidedId } from "../utils/id.js";
3
3
  import { ListboxStates, useActions, useData } from "./Listbox.svelte";
4
4
  import { attemptSubmit } from "../utils/form.js";
5
5
  import { Focus } from "../utils/calculate-active-index.js";
6
6
  import { useFocusRing } from "../hooks/use-focus-ring.svelte.js";
7
7
  import { useActivePress } from "../hooks/use-active-press.svelte.js";
8
8
  import { useResolveButtonType } from "../hooks/use-resolve-button-type.svelte.js";
9
- import { useFloating } from "../internal/floating.svelte.js";
9
+ import { useFloatingReference, useFloatingReferenceProps } from "../internal/floating.svelte.js";
10
10
  import { stateFromSlot } from "../utils/state.js";
11
11
  import { useLabelledBy } from "../label/context.svelte.js";
12
12
  import { useDescribedBy } from "../description/context.svelte.js";
@@ -19,18 +19,18 @@ const DEFAULT_BUTTON_TAG = "button";
19
19
  <script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_BUTTON_TAG">const data = useData("ListboxButton");
20
20
  const actions = useActions("ListboxButton");
21
21
  const internalId = useId();
22
- const providedId = getIdContext();
22
+ const providedId = useProvidedId();
23
23
  let {
24
- as = DEFAULT_BUTTON_TAG,
25
24
  ref = $bindable(),
26
25
  id = providedId || `headlessui-listbox-button-${internalId}`,
27
26
  disabled: ownDisabled = false,
28
27
  autofocus = false,
29
28
  ...theirProps
30
29
  } = $props();
31
- const { setReference, getReferenceProps: getFloatingReferenceProps } = useFloating();
30
+ const { setReference } = useFloatingReference();
31
+ const { getReferenceProps: getFloatingReferenceProps } = useFloatingReferenceProps();
32
32
  $effect(() => {
33
- data.buttonRef.current = ref || null;
33
+ data.buttonElement = ref || null;
34
34
  setReference(ref);
35
35
  });
36
36
  const disabled = $derived(data.disabled || ownDisabled);
@@ -62,7 +62,7 @@ const handleKeyUp = (event) => {
62
62
  const handleClick = (event) => {
63
63
  if (data.listboxState === ListboxStates.Open) {
64
64
  actions.closeListbox();
65
- data.buttonRef.current?.focus({ preventScroll: true });
65
+ data.buttonElement?.focus({ preventScroll: true });
66
66
  } else {
67
67
  event.preventDefault();
68
68
  actions.openListbox();
@@ -104,10 +104,10 @@ const slot = $derived({
104
104
  });
105
105
  const buttonType = useResolveButtonType({
106
106
  get props() {
107
- return { type: theirProps.type, as };
107
+ return { type: theirProps.type, as: theirProps.as };
108
108
  },
109
109
  get ref() {
110
- return data.buttonRef;
110
+ return { current: data.buttonElement };
111
111
  }
112
112
  });
113
113
  const ourProps = $derived(
@@ -117,7 +117,7 @@ const ourProps = $derived(
117
117
  id,
118
118
  type: buttonType.type,
119
119
  "aria-haspopup": "listbox",
120
- "aria-controls": data.optionsRef.current?.id,
120
+ "aria-controls": data.optionsElement?.id,
121
121
  "aria-expanded": data.listboxState === ListboxStates.Open,
122
122
  "aria-labelledby": labelledBy.value,
123
123
  "aria-describedby": describedBy.value,
@@ -1,4 +1,4 @@
1
- import type { ElementType, Props } from "../utils/types.js";
1
+ import type { ElementType, Props, PropsOf } from "../utils/types.js";
2
2
  import type { Snippet } from "svelte";
3
3
  declare const DEFAULT_BUTTON_TAG: "button";
4
4
  type ButtonRenderPropArg = {
@@ -13,7 +13,6 @@ type ButtonRenderPropArg = {
13
13
  };
14
14
  type ButtonPropsWeControl = "aria-controls" | "aria-expanded" | "aria-haspopup" | "aria-labelledby" | "disabled";
15
15
  export type ListboxButtonProps<TTag extends ElementType = typeof DEFAULT_BUTTON_TAG> = Props<TTag, ButtonRenderPropArg, ButtonPropsWeControl, {
16
- id?: string;
17
16
  autofocus?: boolean;
18
17
  disabled?: boolean;
19
18
  }>;
@@ -21,13 +20,12 @@ export type ListboxButtonChildren = Snippet<[ButtonRenderPropArg]>;
21
20
  declare class __sveltets_Render<TTag extends ElementType = typeof DEFAULT_BUTTON_TAG> {
22
21
  props(): {
23
22
  as?: TTag | undefined;
24
- } & (Exclude<keyof import("../utils/types.js").PropsOf<TTag>, ("as" | "children" | "refName" | "class") | "autofocus" | "id" | ButtonPropsWeControl> extends infer T extends keyof import("../utils/types.js").PropsOf<TTag> ? { [P in T]: import("../utils/types.js").PropsOf<TTag>[P]; } : never) & {
25
- children?: import("../utils/types.js").Children<ButtonRenderPropArg> | undefined;
23
+ } & (Exclude<keyof PropsOf<TTag>, ("as" | "children" | "refName" | "class") | "autofocus" | ButtonPropsWeControl> extends infer T extends keyof PropsOf<TTag> ? { [P in T]: PropsOf<TTag>[P]; } : never) & {
24
+ children?: Snippet<[ButtonRenderPropArg, Record<string, any>]> | undefined;
26
25
  ref?: HTMLElement;
27
- } & (true extends (import("../utils/types.js").PropsOf<TTag> extends infer T_1 ? T_1 extends import("../utils/types.js").PropsOf<TTag> ? T_1 extends never ? never : "class" extends infer T_2 ? T_2 extends "class" ? T_2 extends keyof T_1 ? true : never : never : never : never : never) ? {
28
- class?: import("../utils/types.js").PropsOf<TTag>["class"] | ((bag: ButtonRenderPropArg) => string) | undefined;
26
+ } & (true extends (PropsOf<TTag> extends infer T_1 ? T_1 extends PropsOf<TTag> ? T_1 extends never ? never : "class" extends infer T_2 ? T_2 extends "class" ? T_2 extends keyof T_1 ? true : never : never : never : never : never) ? {
27
+ class?: PropsOf<TTag>["class"] | ((bag: ButtonRenderPropArg) => string) | undefined;
29
28
  } : {}) & {
30
- id?: string;
31
29
  autofocus?: boolean;
32
30
  disabled?: boolean;
33
31
  };
@@ -18,7 +18,6 @@ import { stateFromSlot } from "../utils/state.js";
18
18
  import ElementOrComponent from "../utils/ElementOrComponent.svelte";
19
19
  const internalId = useId();
20
20
  let {
21
- as = DEFAULT_OPTION_TAG,
22
21
  ref = $bindable(),
23
22
  id = `headlessui-listbox-option-${internalId}`,
24
23
  disabled = false,
@@ -28,7 +27,8 @@ let {
28
27
  const usedInSelectedOption = getContext("SelectedOptionContext") === true;
29
28
  const data = useData("ListboxOption");
30
29
  const actions = useActions("ListboxOption");
31
- const active = $derived(data.activeOptionIndex !== null ? data.options[data.activeOptionIndex].id === id : false);
30
+ const { activeOptionIndex, options } = $derived(data);
31
+ const active = $derived(activeOptionIndex !== null ? options[activeOptionIndex].id === id : false);
32
32
  const selected = $derived(data.isSelected(value));
33
33
  const getTextValue = useTextValue({
34
34
  get element() {
@@ -44,11 +44,15 @@ const bag = $derived({
44
44
  }
45
45
  });
46
46
  $effect(() => {
47
+ if (usedInSelectedOption) return;
47
48
  if (!ref) {
48
- data.listRef.current.delete(id);
49
+ data.listElements.delete(id);
49
50
  } else {
50
- data.listRef.current.set(id, ref);
51
+ data.listElements.set(id, ref);
51
52
  }
53
+ return () => {
54
+ if (ref) data.listElements.delete(id);
55
+ };
52
56
  });
53
57
  $effect(() => {
54
58
  if (data.__demoMode) return;
@@ -71,9 +75,9 @@ onMount(() => {
71
75
  const handleClick = (event) => {
72
76
  if (disabled) return event.preventDefault();
73
77
  actions.onChange(value);
74
- if (data.mode === ValueMode.Single) {
78
+ if (data.closeOnSelect === true || data.closeOnSelect === void 0 && data.mode === ValueMode.Single) {
75
79
  actions.closeListbox();
76
- data.buttonRef.current?.focus({ preventScroll: true });
80
+ data.buttonElement?.focus({ preventScroll: true });
77
81
  }
78
82
  };
79
83
  const handleFocus = () => {
@@ -20,7 +20,7 @@ declare class __sveltets_Render<TType, TTag extends ElementType = typeof DEFAULT
20
20
  props(): {
21
21
  as?: TTag | undefined;
22
22
  } & (Exclude<keyof import("../utils/types.js").PropsOf<TTag>, ("as" | "children" | "refName" | "class") | "disabled" | "value" | "id" | OptionPropsWeControl> extends infer T extends keyof import("../utils/types.js").PropsOf<TTag> ? { [P in T]: import("../utils/types.js").PropsOf<TTag>[P]; } : never) & {
23
- children?: import("../utils/types.js").Children<OptionRenderPropArg> | undefined;
23
+ children?: Snippet<[OptionRenderPropArg, Record<string, any>]> | undefined;
24
24
  ref?: HTMLElement;
25
25
  } & (true extends (import("../utils/types.js").PropsOf<TTag> extends infer T_1 ? T_1 extends import("../utils/types.js").PropsOf<TTag> ? T_1 extends never ? never : "class" extends infer T_2 ? T_2 extends "class" ? T_2 extends keyof T_1 ? true : never : never : never : never : never) ? {
26
26
  class?: import("../utils/types.js").PropsOf<TTag>["class"] | ((bag: OptionRenderPropArg) => string) | undefined;