@pzerelles/headlessui-svelte 2.1.2-next.32 → 2.1.2-next.34

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 (136) hide show
  1. package/dist/button/Button.svelte +9 -10
  2. package/dist/button/Button.svelte.d.ts +5 -32
  3. package/dist/button/index.d.ts +1 -1
  4. package/dist/checkbox/Checkbox.svelte +15 -12
  5. package/dist/checkbox/Checkbox.svelte.d.ts +15 -32
  6. package/dist/checkbox/index.d.ts +1 -1
  7. package/dist/close-button/CloseButton.svelte +4 -7
  8. package/dist/close-button/CloseButton.svelte.d.ts +2 -43
  9. package/dist/close-button/index.d.ts +1 -0
  10. package/dist/close-button/index.js +1 -0
  11. package/dist/data-interactive/DataInteractive.svelte +6 -20
  12. package/dist/data-interactive/DataInteractive.svelte.d.ts +8 -30
  13. package/dist/data-interactive/index.d.ts +1 -1
  14. package/dist/data-interactive/index.js +1 -1
  15. package/dist/description/Description.svelte +15 -12
  16. package/dist/description/Description.svelte.d.ts +7 -27
  17. package/dist/dialog/Dialog.svelte +34 -32
  18. package/dist/dialog/Dialog.svelte.d.ts +4 -41
  19. package/dist/dialog/DialogBackdrop.svelte +10 -11
  20. package/dist/dialog/DialogBackdrop.svelte.d.ts +5 -29
  21. package/dist/dialog/DialogPanel.svelte +18 -11
  22. package/dist/dialog/DialogPanel.svelte.d.ts +5 -30
  23. package/dist/dialog/DialogTitle.svelte +19 -8
  24. package/dist/dialog/DialogTitle.svelte.d.ts +7 -27
  25. package/dist/dialog/context.svelte.js +1 -1
  26. package/dist/dialog/index.d.ts +4 -4
  27. package/dist/dialog/index.js +3 -3
  28. package/dist/field/Field.svelte +10 -18
  29. package/dist/field/Field.svelte.d.ts +4 -30
  30. package/dist/fieldset/Fieldset.svelte +11 -15
  31. package/dist/fieldset/Fieldset.svelte.d.ts +5 -31
  32. package/dist/focus-trap/FocusTrap.svelte +21 -26
  33. package/dist/focus-trap/FocusTrap.svelte.d.ts +5 -34
  34. package/dist/hooks/use-inert-others.svelte.js +10 -10
  35. package/dist/hooks/use-resolve-button-type.svelte.js +0 -1
  36. package/dist/input/Input.svelte +20 -10
  37. package/dist/input/Input.svelte.d.ts +14 -27
  38. package/dist/input/index.d.ts +1 -1
  39. package/dist/internal/FocusSentinel.svelte +33 -32
  40. package/dist/internal/FormResolver.svelte +5 -1
  41. package/dist/internal/Hidden.svelte +10 -24
  42. package/dist/internal/Hidden.svelte.d.ts +5 -30
  43. package/dist/internal/MainTreeProvider.svelte +1 -1
  44. package/dist/label/Label.svelte +19 -13
  45. package/dist/label/Label.svelte.d.ts +7 -31
  46. package/dist/legend/Legend.svelte +20 -6
  47. package/dist/legend/Legend.svelte.d.ts +4 -3
  48. package/dist/listbox/Listbox.svelte +7 -19
  49. package/dist/listbox/Listbox.svelte.d.ts +12 -35
  50. package/dist/listbox/ListboxButton.svelte +14 -14
  51. package/dist/listbox/ListboxButton.svelte.d.ts +6 -32
  52. package/dist/listbox/ListboxOption.svelte +16 -16
  53. package/dist/listbox/ListboxOption.svelte.d.ts +13 -26
  54. package/dist/listbox/ListboxOptions.svelte +13 -12
  55. package/dist/listbox/ListboxOptions.svelte.d.ts +5 -38
  56. package/dist/listbox/ListboxSelectedOption.svelte +15 -17
  57. package/dist/listbox/ListboxSelectedOption.svelte.d.ts +8 -32
  58. package/dist/listbox/index.d.ts +5 -5
  59. package/dist/listbox/index.js +4 -4
  60. package/dist/menu/Menu.svelte +6 -8
  61. package/dist/menu/Menu.svelte.d.ts +4 -31
  62. package/dist/menu/MenuButton.svelte +13 -13
  63. package/dist/menu/MenuButton.svelte.d.ts +5 -34
  64. package/dist/menu/MenuHeading.svelte +12 -11
  65. package/dist/menu/MenuHeading.svelte.d.ts +4 -31
  66. package/dist/menu/MenuItem.svelte +13 -13
  67. package/dist/menu/MenuItem.svelte.d.ts +6 -32
  68. package/dist/menu/MenuItems.svelte +13 -14
  69. package/dist/menu/MenuItems.svelte.d.ts +5 -38
  70. package/dist/menu/MenuSection.svelte +11 -10
  71. package/dist/menu/MenuSection.svelte.d.ts +5 -29
  72. package/dist/menu/MenuSeparator.svelte +11 -9
  73. package/dist/menu/MenuSeparator.svelte.d.ts +5 -28
  74. package/dist/menu/index.d.ts +4 -4
  75. package/dist/menu/index.js +1 -1
  76. package/dist/popover/Popover.svelte +9 -9
  77. package/dist/popover/Popover.svelte.d.ts +5 -30
  78. package/dist/popover/PopoverBackdrop.svelte +16 -13
  79. package/dist/popover/PopoverBackdrop.svelte.d.ts +7 -34
  80. package/dist/popover/PopoverButton.svelte +34 -34
  81. package/dist/popover/PopoverButton.svelte.d.ts +6 -28
  82. package/dist/popover/PopoverGroup.svelte +15 -17
  83. package/dist/popover/PopoverGroup.svelte.d.ts +5 -28
  84. package/dist/popover/PopoverPanel.svelte +47 -42
  85. package/dist/popover/PopoverPanel.svelte.d.ts +6 -36
  86. package/dist/popover/index.d.ts +4 -4
  87. package/dist/popover/index.js +3 -3
  88. package/dist/portal/InternalPortal.svelte +17 -17
  89. package/dist/portal/InternalPortal.svelte.d.ts +5 -30
  90. package/dist/portal/Portal.svelte +7 -6
  91. package/dist/portal/Portal.svelte.d.ts +2 -18
  92. package/dist/portal/PortalGroup.svelte +6 -14
  93. package/dist/portal/PortalGroup.svelte.d.ts +4 -31
  94. package/dist/select/Select.svelte +11 -10
  95. package/dist/select/Select.svelte.d.ts +6 -32
  96. package/dist/select/index.d.ts +1 -1
  97. package/dist/switch/Switch.svelte +14 -13
  98. package/dist/switch/Switch.svelte.d.ts +6 -38
  99. package/dist/switch/SwitchGroup.svelte +5 -5
  100. package/dist/switch/SwitchGroup.svelte.d.ts +7 -27
  101. package/dist/switch/index.d.ts +1 -1
  102. package/dist/tabs/Tab.svelte +13 -13
  103. package/dist/tabs/Tab.svelte.d.ts +5 -32
  104. package/dist/tabs/TabGroup.svelte +9 -9
  105. package/dist/tabs/TabGroup.svelte.d.ts +5 -34
  106. package/dist/tabs/TabList.svelte +8 -9
  107. package/dist/tabs/TabList.svelte.d.ts +6 -28
  108. package/dist/tabs/TabPanel.svelte +12 -12
  109. package/dist/tabs/TabPanel.svelte.d.ts +5 -34
  110. package/dist/tabs/TabPanels.svelte +6 -6
  111. package/dist/tabs/TabPanels.svelte.d.ts +6 -27
  112. package/dist/tabs/index.d.ts +5 -5
  113. package/dist/tabs/index.js +1 -1
  114. package/dist/textarea/Textarea.svelte +13 -11
  115. package/dist/textarea/Textarea.svelte.d.ts +14 -27
  116. package/dist/textarea/index.d.ts +1 -1
  117. package/dist/transition/InternalTransitionChild.svelte +19 -12
  118. package/dist/transition/InternalTransitionChild.svelte.d.ts +3 -32
  119. package/dist/transition/Transition.svelte +12 -21
  120. package/dist/transition/Transition.svelte.d.ts +3 -35
  121. package/dist/transition/TransitionChild.svelte +9 -10
  122. package/dist/transition/TransitionChild.svelte.d.ts +8 -34
  123. package/dist/transition/context.svelte.js +7 -7
  124. package/dist/transition/index.d.ts +2 -2
  125. package/dist/transition/index.js +1 -1
  126. package/dist/utils/ElementOrComponent.svelte +56 -15
  127. package/dist/utils/ElementOrComponent.svelte.d.ts +30 -23
  128. package/dist/utils/state.js +4 -4
  129. package/dist/utils/types.d.ts +12 -9
  130. package/package.json +12 -12
  131. package/dist/combobox/Combobox.svelte +0 -53
  132. package/dist/combobox/Combobox.svelte.d.ts +0 -50
  133. package/dist/utils/Generic.svelte +0 -57
  134. package/dist/utils/Generic.svelte.d.ts +0 -31
  135. package/dist/utils/alternative-types.d.ts +0 -20
  136. package/dist/utils/alternative-types.js +0 -1
@@ -1,34 +1,8 @@
1
- import type { ElementType, Props } from "../utils/types.js";
1
+ import type { Props } from "../utils/types.js";
2
2
  declare let DEFAULT_FIELD_TAG: "div";
3
- type FieldRenderPropArg = {};
4
- type FieldPropsWeControl = never;
5
- export type FieldProps<TTag extends ElementType = typeof DEFAULT_FIELD_TAG> = Props<TTag, FieldRenderPropArg, FieldPropsWeControl, {
3
+ export type FieldProps = Props<typeof DEFAULT_FIELD_TAG, {}, {
4
+ element?: HTMLElement;
6
5
  disabled?: boolean;
7
6
  }>;
8
- declare class __sveltets_Render<TTag extends ElementType = typeof DEFAULT_FIELD_TAG> {
9
- props(): {
10
- as?: TTag | undefined;
11
- } & (Exclude<keyof import("../utils/types.js").PropsOf<TTag>, ("slot" | "as" | "children" | "class" | "ref") | "disabled"> extends infer T extends keyof import("../utils/types.js").PropsOf<TTag> ? { [P in T]: import("../utils/types.js").PropsOf<TTag>[P]; } : never) & {
12
- children?: import("svelte").Snippet<[{
13
- props?: Record<string, any>;
14
- }]> | undefined;
15
- class?: string | ((bag: FieldRenderPropArg) => string) | null | undefined;
16
- ref?: HTMLElement;
17
- } & {
18
- disabled?: boolean;
19
- };
20
- events(): {};
21
- slots(): {};
22
- bindings(): "ref";
23
- exports(): {};
24
- }
25
- interface $$IsomorphicComponent {
26
- new <TTag extends ElementType = typeof DEFAULT_FIELD_TAG>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<TTag>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<TTag>['props']>, ReturnType<__sveltets_Render<TTag>['events']>, ReturnType<__sveltets_Render<TTag>['slots']>> & {
27
- $$bindings?: ReturnType<__sveltets_Render<TTag>['bindings']>;
28
- } & ReturnType<__sveltets_Render<TTag>['exports']>;
29
- <TTag extends ElementType = typeof DEFAULT_FIELD_TAG>(internal: unknown, props: ReturnType<__sveltets_Render<TTag>['props']> & {}): ReturnType<__sveltets_Render<TTag>['exports']>;
30
- z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
31
- }
32
- declare const Field: $$IsomorphicComponent;
33
- type Field<TTag extends ElementType = typeof DEFAULT_FIELD_TAG> = InstanceType<typeof Field<TTag>>;
7
+ declare const Field: import("svelte").Component<FieldProps, {}, "element">;
34
8
  export default Field;
@@ -1,31 +1,27 @@
1
1
  <script lang="ts" module>
2
- import type { ElementType, Props } from "../utils/types.js"
3
- let DEFAULT_FIELDSET_TAG = "fieldset" as const
2
+ import type { Props } from "../utils/types.js"
3
+
4
+ const DEFAULT_FIELDSET_TAG = "fieldset" as const
4
5
 
5
- type FieldsetRenderPropArg = {}
6
6
  type FieldsetPropsWeControl = "aria-labelledby" | "aria-disabled" | "role"
7
7
 
8
- export type FieldsetProps<TTag extends ElementType = typeof DEFAULT_FIELDSET_TAG> = Props<
9
- TTag,
10
- FieldsetRenderPropArg,
11
- FieldsetPropsWeControl,
8
+ export type FieldsetProps = Props<
9
+ typeof DEFAULT_FIELDSET_TAG,
10
+ {},
12
11
  {
12
+ element?: HTMLElement
13
13
  disabled?: boolean
14
14
  }
15
15
  >
16
16
  </script>
17
17
 
18
- <script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_FIELDSET_TAG">
18
+ <script lang="ts">
19
19
  import { setContext } from "svelte"
20
20
  import { useDisabled } from "../hooks/use-disabled.js"
21
21
  import { useLabels } from "../label/context.svelte.js"
22
22
  import ElementOrComponent from "../utils/ElementOrComponent.svelte"
23
23
 
24
- let {
25
- ref = $bindable(),
26
- disabled: ownDisabled = false,
27
- ...theirProps
28
- }: { as?: TTag } & FieldsetProps<TTag> = $props()
24
+ let { element = $bindable(), disabled: ownDisabled = false, ...theirProps }: FieldsetProps = $props()
29
25
 
30
26
  const providedDisabled = useDisabled()
31
27
  const disabled = $derived(providedDisabled.current || ownDisabled)
@@ -39,7 +35,7 @@
39
35
  const labelledBy = useLabels()
40
36
  const slot = $derived({ disabled })
41
37
  const ourProps = $derived(
42
- (theirProps.as ?? DEFAULT_FIELDSET_TAG) === "fieldset"
38
+ !theirProps.asChild
43
39
  ? {
44
40
  "aria-labelledby": labelledBy.value,
45
41
  disabled: disabled || undefined,
@@ -52,4 +48,4 @@
52
48
  )
53
49
  </script>
54
50
 
55
- <ElementOrComponent {ourProps} {theirProps} {slot} defaultTag={DEFAULT_FIELDSET_TAG} name="Fieldset" bind:ref />
51
+ <ElementOrComponent {ourProps} {theirProps} {slot} defaultTag={DEFAULT_FIELDSET_TAG} name="Fieldset" bind:element />
@@ -1,34 +1,8 @@
1
- import type { ElementType, Props } from "../utils/types.js";
2
- declare let DEFAULT_FIELDSET_TAG: "fieldset";
3
- type FieldsetRenderPropArg = {};
4
- type FieldsetPropsWeControl = "aria-labelledby" | "aria-disabled" | "role";
5
- export type FieldsetProps<TTag extends ElementType = typeof DEFAULT_FIELDSET_TAG> = Props<TTag, FieldsetRenderPropArg, FieldsetPropsWeControl, {
1
+ import type { Props } from "../utils/types.js";
2
+ declare const DEFAULT_FIELDSET_TAG: "fieldset";
3
+ export type FieldsetProps = Props<typeof DEFAULT_FIELDSET_TAG, {}, {
4
+ element?: HTMLElement;
6
5
  disabled?: boolean;
7
6
  }>;
8
- declare class __sveltets_Render<TTag extends ElementType = typeof DEFAULT_FIELDSET_TAG> {
9
- props(): {
10
- as?: TTag | undefined;
11
- } & (Exclude<keyof import("../utils/types.js").PropsOf<TTag>, ("slot" | "as" | "children" | "class" | "ref") | "disabled" | FieldsetPropsWeControl> extends infer T extends keyof import("../utils/types.js").PropsOf<TTag> ? { [P in T]: import("../utils/types.js").PropsOf<TTag>[P]; } : never) & {
12
- children?: import("svelte").Snippet<[{
13
- props?: Record<string, any>;
14
- }]> | undefined;
15
- class?: string | ((bag: FieldsetRenderPropArg) => string) | null | undefined;
16
- ref?: HTMLElement;
17
- } & {
18
- disabled?: boolean;
19
- };
20
- events(): {};
21
- slots(): {};
22
- bindings(): "ref";
23
- exports(): {};
24
- }
25
- interface $$IsomorphicComponent {
26
- new <TTag extends ElementType = typeof DEFAULT_FIELDSET_TAG>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<TTag>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<TTag>['props']>, ReturnType<__sveltets_Render<TTag>['events']>, ReturnType<__sveltets_Render<TTag>['slots']>> & {
27
- $$bindings?: ReturnType<__sveltets_Render<TTag>['bindings']>;
28
- } & ReturnType<__sveltets_Render<TTag>['exports']>;
29
- <TTag extends ElementType = typeof DEFAULT_FIELDSET_TAG>(internal: unknown, props: ReturnType<__sveltets_Render<TTag>['props']> & {}): ReturnType<__sveltets_Render<TTag>['exports']>;
30
- z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
31
- }
32
- declare const Fieldset: $$IsomorphicComponent;
33
- type Fieldset<TTag extends ElementType = typeof DEFAULT_FIELDSET_TAG> = InstanceType<typeof Fieldset<TTag>>;
7
+ declare const Fieldset: import("svelte").Component<FieldsetProps, {}, "element">;
34
8
  export default Fieldset;
@@ -1,6 +1,6 @@
1
1
  <script lang="ts" module>
2
2
  import { getOwnerDocument } from "../utils/owner.js"
3
- import type { ElementType, Props } from "../utils/types.js"
3
+ import type { Props } from "../utils/types.js"
4
4
  import { history } from "../utils/active-element-history.js"
5
5
  import { useWatch } from "../hooks/use-watch.svelte.js"
6
6
  import { microTask } from "../utils/microTask.js"
@@ -35,18 +35,17 @@
35
35
  return all
36
36
  }
37
37
 
38
- let DEFAULT_FOCUS_TRAP_TAG = "div" as const
38
+ const DEFAULT_FOCUS_TRAP_TAG = "div" as const
39
39
 
40
40
  export * from "./FocusTrapFeatures.js"
41
41
 
42
- type FocusTrapRenderPropArg = {}
43
42
  type FocusTrapPropsWeControl = never
44
43
 
45
- export type FocusTrapProps<TTag extends ElementType = typeof DEFAULT_FOCUS_TRAP_TAG> = Props<
46
- TTag,
47
- FocusTrapRenderPropArg,
48
- FocusTrapPropsWeControl,
44
+ export type FocusTrapProps = Props<
45
+ typeof DEFAULT_FOCUS_TRAP_TAG,
46
+ {},
49
47
  {
48
+ element?: HTMLElement
50
49
  initialFocus?: HTMLElement
51
50
  // A fallback element to focus, but this element will be skipped when tabbing around. This is
52
51
  // only done for focusing a fallback parent container (e.g.: A `Dialog`, but you want to tab
@@ -293,10 +292,10 @@
293
292
  }
294
293
  </script>
295
294
 
296
- <script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_FOCUS_TRAP_TAG">
295
+ <script lang="ts">
297
296
  let container = $state<HTMLElement | null>(null)
298
297
  let {
299
- ref = $bindable(),
298
+ element = $bindable(),
300
299
  initialFocus,
301
300
  initialFocusFallback,
302
301
  containers,
@@ -305,13 +304,13 @@
305
304
  FocusTrapFeatures.FocusLock |
306
305
  FocusTrapFeatures.RestoreFocus,
307
306
  ...theirProps
308
- }: { as?: TTag } & FocusTrapProps<TTag> = $props()
307
+ }: FocusTrapProps = $props()
309
308
 
310
309
  /*if (!useServerHandoffComplete()) {
311
310
  features = FocusTrapFeatures.None
312
311
  }*/
313
312
 
314
- const ownerDocument = $derived(getOwnerDocument(ref))
313
+ const ownerDocument = $derived(getOwnerDocument(element))
315
314
 
316
315
  useRestoreFocus({
317
316
  get features() {
@@ -441,21 +440,17 @@
441
440
  </script>
442
441
 
443
442
  {#if tabLockEnabled}
444
- <Hidden
445
- as="button"
446
- type="button"
447
- data-headlessui-focus-guard
448
- onfocus={handleFocus}
449
- features={HiddenFeatures.Focusable}
450
- />
443
+ <Hidden asChild features={HiddenFeatures.Focusable}>
444
+ {#snippet children({ props })}
445
+ <button {...props} type="button" data-headlessui-focus-guard onfocus={handleFocus}>&zwnj;</button>
446
+ {/snippet}
447
+ </Hidden>
451
448
  {/if}
452
- <ElementOrComponent {ourProps} {theirProps} defaultTag={DEFAULT_FOCUS_TRAP_TAG} name="FocusTrap" bind:ref />
449
+ <ElementOrComponent {ourProps} {theirProps} defaultTag={DEFAULT_FOCUS_TRAP_TAG} name="FocusTrap" bind:element />
453
450
  {#if tabLockEnabled}
454
- <Hidden
455
- as="button"
456
- type="button"
457
- data-headlessui-focus-guard
458
- onfocus={handleFocus}
459
- features={HiddenFeatures.Focusable}
460
- />
451
+ <Hidden asChild features={HiddenFeatures.Focusable}>
452
+ {#snippet children({ props })}
453
+ <button {...props} type="button" data-headlessui-focus-guard onfocus={handleFocus}>&zwnj;</button>
454
+ {/snippet}
455
+ </Hidden>
461
456
  {/if}
@@ -1,43 +1,14 @@
1
- import type { ElementType, Props } from "../utils/types.js";
1
+ import type { Props } from "../utils/types.js";
2
2
  import { FocusTrapFeatures } from "./FocusTrapFeatures.js";
3
3
  type Containers = (() => Iterable<HTMLElement>) | Iterable<HTMLElement>;
4
- declare let DEFAULT_FOCUS_TRAP_TAG: "div";
4
+ declare const DEFAULT_FOCUS_TRAP_TAG: "div";
5
5
  export * from "./FocusTrapFeatures.js";
6
- type FocusTrapRenderPropArg = {};
7
- type FocusTrapPropsWeControl = never;
8
- export type FocusTrapProps<TTag extends ElementType = typeof DEFAULT_FOCUS_TRAP_TAG> = Props<TTag, FocusTrapRenderPropArg, FocusTrapPropsWeControl, {
6
+ export type FocusTrapProps = Props<typeof DEFAULT_FOCUS_TRAP_TAG, {}, {
7
+ element?: HTMLElement;
9
8
  initialFocus?: HTMLElement;
10
9
  initialFocusFallback?: HTMLElement;
11
10
  features?: FocusTrapFeatures;
12
11
  containers?: Containers;
13
12
  }>;
14
- declare class __sveltets_Render<TTag extends ElementType = typeof DEFAULT_FOCUS_TRAP_TAG> {
15
- props(): {
16
- as?: TTag | undefined;
17
- } & (Exclude<keyof import("../utils/types.js").PropsOf<TTag>, ("slot" | "as" | "children" | "class" | "ref") | "features" | "containers" | "initialFocus" | "initialFocusFallback"> extends infer T extends keyof import("../utils/types.js").PropsOf<TTag> ? { [P in T]: import("../utils/types.js").PropsOf<TTag>[P]; } : never) & {
18
- children?: import("svelte").Snippet<[{
19
- props?: Record<string, any>;
20
- }]> | undefined;
21
- class?: string | ((bag: FocusTrapRenderPropArg) => string) | null | undefined;
22
- ref?: HTMLElement;
23
- } & {
24
- initialFocus?: HTMLElement;
25
- initialFocusFallback?: HTMLElement;
26
- features?: FocusTrapFeatures;
27
- containers?: Containers;
28
- };
29
- events(): {};
30
- slots(): {};
31
- bindings(): "ref";
32
- exports(): {};
33
- }
34
- interface $$IsomorphicComponent {
35
- new <TTag extends ElementType = typeof DEFAULT_FOCUS_TRAP_TAG>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<TTag>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<TTag>['props']>, ReturnType<__sveltets_Render<TTag>['events']>, ReturnType<__sveltets_Render<TTag>['slots']>> & {
36
- $$bindings?: ReturnType<__sveltets_Render<TTag>['bindings']>;
37
- } & ReturnType<__sveltets_Render<TTag>['exports']>;
38
- <TTag extends ElementType = typeof DEFAULT_FOCUS_TRAP_TAG>(internal: unknown, props: ReturnType<__sveltets_Render<TTag>['props']> & {}): ReturnType<__sveltets_Render<TTag>['exports']>;
39
- z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
40
- }
41
- declare const FocusTrap: $$IsomorphicComponent;
42
- type FocusTrap<TTag extends ElementType = typeof DEFAULT_FOCUS_TRAP_TAG> = InstanceType<typeof FocusTrap<TTag>>;
13
+ declare const FocusTrap: import("svelte").Component<FocusTrapProps, {}, "element">;
43
14
  export default FocusTrap;
@@ -5,7 +5,7 @@ const originals = new Map();
5
5
  const counts = new Map();
6
6
  function markInert(element) {
7
7
  // Increase count
8
- let count = counts.get(element) ?? 0;
8
+ const count = counts.get(element) ?? 0;
9
9
  counts.set(element, count + 1);
10
10
  // Already marked as inert, no need to do it again
11
11
  if (count !== 0)
@@ -22,7 +22,7 @@ function markInert(element) {
22
22
  }
23
23
  function markNotInert(element) {
24
24
  // Decrease counts
25
- let count = counts.get(element) ?? 1; // Should always exist
25
+ const count = counts.get(element) ?? 1; // Should always exist
26
26
  if (count === 1)
27
27
  counts.delete(element); // We are the last one, so we can delete the count
28
28
  else
@@ -30,7 +30,7 @@ function markNotInert(element) {
30
30
  // Not the last one, so we don't restore the original values (yet)
31
31
  if (count !== 1)
32
32
  return;
33
- let original = originals.get(element);
33
+ const original = originals.get(element);
34
34
  if (!original)
35
35
  return; // Should never happen
36
36
  // Restore original values
@@ -70,7 +70,7 @@ function markNotInert(element) {
70
70
  export function useInertOthers(options) {
71
71
  const { enabled, elements } = $derived(options);
72
72
  const { allowed, disallowed } = $derived(elements ?? {});
73
- let isTopLayer = useIsTopLayer({
73
+ const isTopLayer = useIsTopLayer({
74
74
  get enabled() {
75
75
  return enabled;
76
76
  },
@@ -79,25 +79,25 @@ export function useInertOthers(options) {
79
79
  $effect(() => {
80
80
  if (!isTopLayer.value)
81
81
  return;
82
- let d = disposables();
82
+ const d = disposables();
83
83
  // Mark all disallowed elements as inert
84
- for (let element of disallowed ?? []) {
84
+ for (const element of disallowed ?? []) {
85
85
  if (!element)
86
86
  continue;
87
87
  d.add(markInert(element));
88
88
  }
89
89
  // Mark all siblings of allowed elements (and parents) as inert
90
- let allowedElements = allowed ?? [];
91
- for (let element of allowedElements) {
90
+ const allowedElements = allowed ?? [];
91
+ for (const element of allowedElements) {
92
92
  if (!element)
93
93
  continue;
94
- let ownerDocument = getOwnerDocument(element);
94
+ const ownerDocument = getOwnerDocument(element);
95
95
  if (!ownerDocument)
96
96
  continue;
97
97
  let parent = element.parentElement;
98
98
  while (parent && parent !== ownerDocument.body) {
99
99
  // Mark all siblings as inert
100
- for (let node of parent.children) {
100
+ for (const node of parent.children) {
101
101
  // If the node contains any of the elements we should not mark it as inert
102
102
  // because it would make the elements unreachable.
103
103
  if (node.tagName.toLowerCase() === "svelte:fragment" || allowedElements.some((el) => node.contains(el)))
@@ -1,4 +1,3 @@
1
- import { untrack } from "svelte";
2
1
  function resolveType(props) {
3
2
  if (props.type)
4
3
  return props.type;
@@ -1,9 +1,10 @@
1
1
  <script lang="ts" module>
2
- import type { ElementType, Props, PropsOf } from "../utils/types.js"
2
+ import type { Props } from "../utils/types.js"
3
+ import type { SvelteHTMLElements } from "svelte/elements"
3
4
 
4
5
  const DEFAULT_INPUT_TAG = "input" as const
5
6
 
6
- type InputRenderPropArg = {
7
+ export type InputRenderPropArg = {
7
8
  disabled: boolean
8
9
  hover: boolean
9
10
  focus: boolean
@@ -12,11 +13,12 @@
12
13
  }
13
14
  type InputPropsWeControl = "aria-labelledby" | "aria-describedby"
14
15
 
15
- export type InputProps<TTag extends ElementType = typeof DEFAULT_INPUT_TAG, TValue = string> = Props<
16
- TTag,
16
+ export type InputProps<TValue = string> = Props<
17
+ typeof DEFAULT_INPUT_TAG,
17
18
  InputRenderPropArg,
18
- InputPropsWeControl,
19
19
  {
20
+ element?: HTMLElement
21
+ id?: string
20
22
  value?: TValue
21
23
  disabled?: boolean
22
24
  invalid?: boolean
@@ -25,7 +27,7 @@
25
27
  >
26
28
  </script>
27
29
 
28
- <script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_INPUT_TAG, TValue = string">
30
+ <script lang="ts" generics="TValue = string">
29
31
  import { htmlid } from "../utils/id.js"
30
32
  import { useDisabled } from "../hooks/use-disabled.js"
31
33
  import { useProvidedId } from "../utils/id.js"
@@ -41,14 +43,14 @@
41
43
  const providedDisabled = useDisabled()
42
44
 
43
45
  let {
44
- ref = $bindable(),
46
+ element = $bindable(),
45
47
  value = $bindable(),
46
- id = (providedId || `headlessui-input-${internalId}`) as PropsOf<TTag>["id"],
48
+ id = providedId || `headlessui-input-${internalId}`,
47
49
  disabled: theirDisabled = false,
48
50
  autofocus = false,
49
51
  invalid = false,
50
52
  ...theirProps
51
- }: { as?: TTag; value?: TValue } & InputProps<TTag, TValue> = $props()
53
+ }: InputProps<TValue> = $props()
52
54
  const disabled = $derived(providedDisabled.current || theirDisabled)
53
55
 
54
56
  const labelledBy = useLabelledBy()
@@ -87,4 +89,12 @@
87
89
  const slot = $derived({ disabled, invalid, hover, focus, autofocus } satisfies InputRenderPropArg)
88
90
  </script>
89
91
 
90
- <ElementOrComponent {ourProps} {theirProps} {slot} defaultTag={DEFAULT_INPUT_TAG} name="Input" bind:ref bind:value />
92
+ <ElementOrComponent
93
+ {ourProps}
94
+ {theirProps}
95
+ {slot}
96
+ defaultTag={DEFAULT_INPUT_TAG}
97
+ name="Input"
98
+ bind:element
99
+ bind:value
100
+ />
@@ -1,47 +1,34 @@
1
- import type { ElementType, Props, PropsOf } from "../utils/types.js";
1
+ import type { Props } from "../utils/types.js";
2
2
  declare const DEFAULT_INPUT_TAG: "input";
3
- type InputRenderPropArg = {
3
+ export type InputRenderPropArg = {
4
4
  disabled: boolean;
5
5
  hover: boolean;
6
6
  focus: boolean;
7
7
  autofocus: boolean;
8
8
  invalid: boolean;
9
9
  };
10
- type InputPropsWeControl = "aria-labelledby" | "aria-describedby";
11
- export type InputProps<TTag extends ElementType = typeof DEFAULT_INPUT_TAG, TValue = string> = Props<TTag, InputRenderPropArg, InputPropsWeControl, {
10
+ export type InputProps<TValue = string> = Props<typeof DEFAULT_INPUT_TAG, InputRenderPropArg, {
11
+ element?: HTMLElement;
12
+ id?: string;
12
13
  value?: TValue;
13
14
  disabled?: boolean;
14
15
  invalid?: boolean;
15
16
  autofocus?: boolean;
16
17
  }>;
17
- declare class __sveltets_Render<TTag extends ElementType = typeof DEFAULT_INPUT_TAG, TValue = string> {
18
- props(): {
19
- as?: TTag | undefined;
20
- value?: TValue | undefined;
21
- } & (Exclude<keyof PropsOf<TTag>, ("slot" | "as" | "children" | "class" | "ref") | "invalid" | "disabled" | "autofocus" | "value" | InputPropsWeControl> extends infer T extends keyof PropsOf<TTag> ? { [P in T]: PropsOf<TTag>[P]; } : never) & {
22
- children?: import("svelte").Snippet<[InputRenderPropArg & {
23
- props?: Record<string, any>;
24
- }]> | undefined;
25
- class?: string | ((bag: InputRenderPropArg) => string) | null | undefined;
26
- ref?: HTMLElement;
27
- } & {
28
- value?: TValue | undefined;
29
- disabled?: boolean;
30
- invalid?: boolean;
31
- autofocus?: boolean;
32
- };
18
+ declare class __sveltets_Render<TValue = string> {
19
+ props(): InputProps<TValue>;
33
20
  events(): {};
34
21
  slots(): {};
35
- bindings(): "ref" | "value";
22
+ bindings(): "element" | "value";
36
23
  exports(): {};
37
24
  }
38
25
  interface $$IsomorphicComponent {
39
- new <TTag extends ElementType = typeof DEFAULT_INPUT_TAG, TValue = string>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<TTag, TValue>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<TTag, TValue>['props']>, ReturnType<__sveltets_Render<TTag, TValue>['events']>, ReturnType<__sveltets_Render<TTag, TValue>['slots']>> & {
40
- $$bindings?: ReturnType<__sveltets_Render<TTag, TValue>['bindings']>;
41
- } & ReturnType<__sveltets_Render<TTag, TValue>['exports']>;
42
- <TTag extends ElementType = typeof DEFAULT_INPUT_TAG, TValue = string>(internal: unknown, props: ReturnType<__sveltets_Render<TTag, TValue>['props']> & {}): ReturnType<__sveltets_Render<TTag, TValue>['exports']>;
43
- z_$$bindings?: ReturnType<__sveltets_Render<any, any>['bindings']>;
26
+ new <TValue = string>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<TValue>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<TValue>['props']>, ReturnType<__sveltets_Render<TValue>['events']>, ReturnType<__sveltets_Render<TValue>['slots']>> & {
27
+ $$bindings?: ReturnType<__sveltets_Render<TValue>['bindings']>;
28
+ } & ReturnType<__sveltets_Render<TValue>['exports']>;
29
+ <TValue = string>(internal: unknown, props: ReturnType<__sveltets_Render<TValue>['props']> & {}): ReturnType<__sveltets_Render<TValue>['exports']>;
30
+ z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
44
31
  }
45
32
  declare const Input: $$IsomorphicComponent;
46
- type Input<TTag extends ElementType = typeof DEFAULT_INPUT_TAG, TValue = string> = InstanceType<typeof Input<TTag, TValue>>;
33
+ type Input<TValue = string> = InstanceType<typeof Input<TValue>>;
47
34
  export default Input;
@@ -1 +1 @@
1
- export { default as Input, type InputProps } from "./Input.svelte";
1
+ export { default as Input, type InputProps, type InputRenderPropArg as InputSlot } from "./Input.svelte";
@@ -14,40 +14,41 @@
14
14
  onMount(() => {
15
15
  mounted = true
16
16
  })
17
- </script>
18
17
 
19
- {#if enabled}
20
- <Hidden
21
- as="button"
22
- type="button"
23
- features={HiddenFeatures.Focusable}
24
- onfocus={(event: FocusEvent) => {
25
- event.preventDefault()
26
- let frame: ReturnType<typeof requestAnimationFrame>
27
-
28
- let tries = 50
29
- function forwardFocus() {
30
- // Prevent infinite loops
31
- if (tries-- <= 0) {
32
- if (frame) cancelAnimationFrame(frame)
33
- return
34
- }
35
-
36
- // Try to move focus to the correct element. This depends on the implementation
37
- // of `onFocus` of course since it would be different for each place we use it in.
38
- if (onfocus?.()) {
39
- cancelAnimationFrame(frame)
40
- if (!mounted) return
41
-
42
- enabled = false
43
- return
44
- }
45
-
46
- // Retry
47
- frame = requestAnimationFrame(forwardFocus)
18
+ const handleFocus = (event: FocusEvent) => {
19
+ event.preventDefault()
20
+ let frame: ReturnType<typeof requestAnimationFrame>
21
+
22
+ let tries = 50
23
+ function forwardFocus() {
24
+ // Prevent infinite loops
25
+ if (tries-- <= 0) {
26
+ if (frame) cancelAnimationFrame(frame)
27
+ return
28
+ }
29
+
30
+ // Try to move focus to the correct element. This depends on the implementation
31
+ // of `onFocus` of course since it would be different for each place we use it in.
32
+ if (onfocus?.()) {
33
+ cancelAnimationFrame(frame)
34
+ if (!mounted) return
35
+
36
+ enabled = false
37
+ return
48
38
  }
49
39
 
40
+ // Retry
50
41
  frame = requestAnimationFrame(forwardFocus)
51
- }}
52
- />
42
+ }
43
+
44
+ frame = requestAnimationFrame(forwardFocus)
45
+ }
46
+ </script>
47
+
48
+ {#if enabled}
49
+ <Hidden asChild features={HiddenFeatures.Focusable}>
50
+ {#snippet children({ props })}
51
+ <button {...props} type="button" onfocus={handleFocus}>&zwnj;</button>
52
+ {/snippet}
53
+ </Hidden>
53
54
  {/if}
@@ -21,5 +21,9 @@
21
21
  </script>
22
22
 
23
23
  {#if !formId}
24
- <Hidden features={HiddenFeatures.Hidden} as="input" type="hidden" hidden readonly bind:ref={element} />
24
+ <Hidden asChild features={HiddenFeatures.Hidden}>
25
+ {#snippet children({ props })}
26
+ <input {...props} type="hidden" hidden readonly bind:this={element} />
27
+ {/snippet}
28
+ </Hidden>
25
29
  {/if}
@@ -1,36 +1,30 @@
1
1
  <script lang="ts" module>
2
2
  import ElementOrComponent from "../utils/ElementOrComponent.svelte"
3
- import type { ElementType, Props } from "../utils/types.js"
3
+ import type { Props } from "../utils/types.js"
4
4
  import { HiddenFeatures } from "./HiddenFeatures.js"
5
+ import type { SvelteHTMLElements } from "svelte/elements"
5
6
 
6
7
  export * from "./HiddenFeatures.js"
7
8
 
8
9
  const DEFAULT_VISUALLY_HIDDEN_TAG = "span" as const
9
10
 
10
- type HiddenRenderPropArg = {}
11
+ export type HiddenRenderPropArg = {}
11
12
  type HiddenPropsWeControl = never
12
- export type HiddenProps<TTag extends ElementType = typeof DEFAULT_VISUALLY_HIDDEN_TAG> = Props<
13
- TTag,
13
+ export type HiddenProps = Props<
14
+ typeof DEFAULT_VISUALLY_HIDDEN_TAG,
14
15
  HiddenRenderPropArg,
15
- HiddenPropsWeControl,
16
- { features?: HiddenFeatures }
16
+ { element?: HTMLElement; features?: HiddenFeatures }
17
17
  >
18
18
  </script>
19
19
 
20
- <script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_VISUALLY_HIDDEN_TAG">
21
- let {
22
- ref = $bindable(),
23
- value,
24
- checked,
25
- features = HiddenFeatures.None,
26
- ...theirProps
27
- }: { as?: TTag } & HiddenProps<TTag> = $props()
20
+ <script lang="ts">
21
+ let { element = $bindable(), features = HiddenFeatures.None, ...theirProps }: HiddenProps = $props()
28
22
 
29
23
  let ourProps = {
30
24
  "aria-hidden":
31
25
  (features & HiddenFeatures.Focusable) === HiddenFeatures.Focusable
32
26
  ? true
33
- : (theirProps["aria-hidden" as keyof typeof theirProps] ?? undefined),
27
+ : (theirProps["aria-hidden"] ?? undefined),
34
28
  hidden: (features & HiddenFeatures.Hidden) === HiddenFeatures.Hidden ? true : undefined,
35
29
  style: [
36
30
  "position: fixed",
@@ -52,12 +46,4 @@
52
46
  }
53
47
  </script>
54
48
 
55
- <ElementOrComponent
56
- {ourProps}
57
- {theirProps}
58
- defaultTag={DEFAULT_VISUALLY_HIDDEN_TAG}
59
- name="Hidden"
60
- bind:ref
61
- {value}
62
- {checked}
63
- />
49
+ <ElementOrComponent {ourProps} {theirProps} defaultTag={DEFAULT_VISUALLY_HIDDEN_TAG} name="Hidden" bind:element />