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

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 (114) hide show
  1. package/dist/button/Button.svelte +8 -9
  2. package/dist/button/Button.svelte.d.ts +4 -31
  3. package/dist/checkbox/Checkbox.svelte +14 -11
  4. package/dist/checkbox/Checkbox.svelte.d.ts +14 -31
  5. package/dist/close-button/CloseButton.svelte +4 -7
  6. package/dist/close-button/CloseButton.svelte.d.ts +2 -43
  7. package/dist/data-interactive/DataInteractive.svelte +5 -19
  8. package/dist/data-interactive/DataInteractive.svelte.d.ts +7 -29
  9. package/dist/description/Description.svelte +15 -12
  10. package/dist/description/Description.svelte.d.ts +7 -27
  11. package/dist/dialog/Dialog.svelte +34 -32
  12. package/dist/dialog/Dialog.svelte.d.ts +4 -41
  13. package/dist/dialog/DialogBackdrop.svelte +10 -10
  14. package/dist/dialog/DialogBackdrop.svelte.d.ts +4 -28
  15. package/dist/dialog/DialogPanel.svelte +18 -10
  16. package/dist/dialog/DialogPanel.svelte.d.ts +4 -29
  17. package/dist/dialog/DialogTitle.svelte +19 -7
  18. package/dist/dialog/DialogTitle.svelte.d.ts +6 -26
  19. package/dist/field/Field.svelte +9 -15
  20. package/dist/field/Field.svelte.d.ts +4 -29
  21. package/dist/fieldset/Fieldset.svelte +10 -13
  22. package/dist/fieldset/Fieldset.svelte.d.ts +5 -30
  23. package/dist/focus-trap/FocusTrap.svelte +20 -24
  24. package/dist/focus-trap/FocusTrap.svelte.d.ts +5 -33
  25. package/dist/hooks/use-inert-others.svelte.js +10 -10
  26. package/dist/hooks/use-resolve-button-type.svelte.js +0 -1
  27. package/dist/input/Input.svelte +19 -9
  28. package/dist/input/Input.svelte.d.ts +13 -26
  29. package/dist/internal/FocusSentinel.svelte +33 -32
  30. package/dist/internal/FormResolver.svelte +5 -1
  31. package/dist/internal/Hidden.svelte +9 -23
  32. package/dist/internal/Hidden.svelte.d.ts +4 -29
  33. package/dist/internal/MainTreeProvider.svelte +1 -1
  34. package/dist/label/Label.svelte +19 -13
  35. package/dist/label/Label.svelte.d.ts +7 -31
  36. package/dist/legend/Legend.svelte +20 -6
  37. package/dist/legend/Legend.svelte.d.ts +4 -3
  38. package/dist/listbox/Listbox.svelte +6 -17
  39. package/dist/listbox/Listbox.svelte.d.ts +11 -34
  40. package/dist/listbox/ListboxButton.svelte +14 -13
  41. package/dist/listbox/ListboxButton.svelte.d.ts +5 -31
  42. package/dist/listbox/ListboxOption.svelte +15 -15
  43. package/dist/listbox/ListboxOption.svelte.d.ts +12 -25
  44. package/dist/listbox/ListboxOptions.svelte +13 -11
  45. package/dist/listbox/ListboxOptions.svelte.d.ts +4 -37
  46. package/dist/listbox/ListboxSelectedOption.svelte +15 -17
  47. package/dist/listbox/ListboxSelectedOption.svelte.d.ts +8 -32
  48. package/dist/menu/Menu.svelte +5 -7
  49. package/dist/menu/Menu.svelte.d.ts +3 -30
  50. package/dist/menu/MenuButton.svelte +12 -12
  51. package/dist/menu/MenuButton.svelte.d.ts +4 -33
  52. package/dist/menu/MenuHeading.svelte +10 -9
  53. package/dist/menu/MenuHeading.svelte.d.ts +4 -30
  54. package/dist/menu/MenuItem.svelte +12 -12
  55. package/dist/menu/MenuItem.svelte.d.ts +5 -31
  56. package/dist/menu/MenuItems.svelte +12 -13
  57. package/dist/menu/MenuItems.svelte.d.ts +4 -37
  58. package/dist/menu/MenuSection.svelte +9 -8
  59. package/dist/menu/MenuSection.svelte.d.ts +5 -28
  60. package/dist/menu/MenuSeparator.svelte +9 -7
  61. package/dist/menu/MenuSeparator.svelte.d.ts +5 -27
  62. package/dist/popover/Popover.svelte +8 -8
  63. package/dist/popover/Popover.svelte.d.ts +4 -29
  64. package/dist/popover/PopoverBackdrop.svelte +15 -12
  65. package/dist/popover/PopoverBackdrop.svelte.d.ts +6 -33
  66. package/dist/popover/PopoverButton.svelte +34 -34
  67. package/dist/popover/PopoverButton.svelte.d.ts +6 -28
  68. package/dist/popover/PopoverGroup.svelte +14 -13
  69. package/dist/popover/PopoverGroup.svelte.d.ts +5 -27
  70. package/dist/popover/PopoverPanel.svelte +46 -41
  71. package/dist/popover/PopoverPanel.svelte.d.ts +5 -35
  72. package/dist/popover/index.d.ts +1 -1
  73. package/dist/portal/InternalPortal.svelte +17 -16
  74. package/dist/portal/InternalPortal.svelte.d.ts +4 -29
  75. package/dist/portal/Portal.svelte +7 -6
  76. package/dist/portal/Portal.svelte.d.ts +2 -18
  77. package/dist/portal/PortalGroup.svelte +5 -13
  78. package/dist/portal/PortalGroup.svelte.d.ts +3 -30
  79. package/dist/select/Select.svelte +10 -9
  80. package/dist/select/Select.svelte.d.ts +5 -31
  81. package/dist/switch/Switch.svelte +13 -12
  82. package/dist/switch/Switch.svelte.d.ts +5 -37
  83. package/dist/switch/SwitchGroup.svelte +5 -5
  84. package/dist/switch/SwitchGroup.svelte.d.ts +7 -27
  85. package/dist/tabs/Tab.svelte +12 -12
  86. package/dist/tabs/Tab.svelte.d.ts +4 -31
  87. package/dist/tabs/TabGroup.svelte +8 -8
  88. package/dist/tabs/TabGroup.svelte.d.ts +4 -33
  89. package/dist/tabs/TabList.svelte +7 -8
  90. package/dist/tabs/TabList.svelte.d.ts +5 -27
  91. package/dist/tabs/TabPanel.svelte +11 -11
  92. package/dist/tabs/TabPanel.svelte.d.ts +4 -33
  93. package/dist/tabs/TabPanels.svelte +5 -5
  94. package/dist/tabs/TabPanels.svelte.d.ts +5 -26
  95. package/dist/textarea/Textarea.svelte +12 -10
  96. package/dist/textarea/Textarea.svelte.d.ts +13 -26
  97. package/dist/transition/InternalTransitionChild.svelte +19 -12
  98. package/dist/transition/InternalTransitionChild.svelte.d.ts +3 -32
  99. package/dist/transition/Transition.svelte +12 -21
  100. package/dist/transition/Transition.svelte.d.ts +3 -35
  101. package/dist/transition/TransitionChild.svelte +9 -10
  102. package/dist/transition/TransitionChild.svelte.d.ts +8 -34
  103. package/dist/transition/context.svelte.js +7 -7
  104. package/dist/utils/ElementOrComponent.svelte +56 -15
  105. package/dist/utils/ElementOrComponent.svelte.d.ts +30 -23
  106. package/dist/utils/state.js +4 -4
  107. package/dist/utils/types.d.ts +12 -9
  108. package/package.json +12 -12
  109. package/dist/combobox/Combobox.svelte +0 -53
  110. package/dist/combobox/Combobox.svelte.d.ts +0 -50
  111. package/dist/utils/Generic.svelte +0 -57
  112. package/dist/utils/Generic.svelte.d.ts +0 -31
  113. package/dist/utils/alternative-types.d.ts +0 -20
  114. package/dist/utils/alternative-types.js +0 -1
@@ -1,31 +1,28 @@
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
6
  type FieldsetRenderPropArg = {}
6
7
  type FieldsetPropsWeControl = "aria-labelledby" | "aria-disabled" | "role"
7
8
 
8
- export type FieldsetProps<TTag extends ElementType = typeof DEFAULT_FIELDSET_TAG> = Props<
9
- TTag,
9
+ export type FieldsetProps = Props<
10
+ typeof DEFAULT_FIELDSET_TAG,
10
11
  FieldsetRenderPropArg,
11
- FieldsetPropsWeControl,
12
12
  {
13
+ element?: HTMLElement
13
14
  disabled?: boolean
14
15
  }
15
16
  >
16
17
  </script>
17
18
 
18
- <script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_FIELDSET_TAG">
19
+ <script lang="ts">
19
20
  import { setContext } from "svelte"
20
21
  import { useDisabled } from "../hooks/use-disabled.js"
21
22
  import { useLabels } from "../label/context.svelte.js"
22
23
  import ElementOrComponent from "../utils/ElementOrComponent.svelte"
23
24
 
24
- let {
25
- ref = $bindable(),
26
- disabled: ownDisabled = false,
27
- ...theirProps
28
- }: { as?: TTag } & FieldsetProps<TTag> = $props()
25
+ let { element = $bindable(), disabled: ownDisabled = false, ...theirProps }: FieldsetProps = $props()
29
26
 
30
27
  const providedDisabled = useDisabled()
31
28
  const disabled = $derived(providedDisabled.current || ownDisabled)
@@ -39,7 +36,7 @@
39
36
  const labelledBy = useLabels()
40
37
  const slot = $derived({ disabled })
41
38
  const ourProps = $derived(
42
- (theirProps.as ?? DEFAULT_FIELDSET_TAG) === "fieldset"
39
+ !theirProps.asChild
43
40
  ? {
44
41
  "aria-labelledby": labelledBy.value,
45
42
  disabled: disabled || undefined,
@@ -52,4 +49,4 @@
52
49
  )
53
50
  </script>
54
51
 
55
- <ElementOrComponent {ourProps} {theirProps} {slot} defaultTag={DEFAULT_FIELDSET_TAG} name="Fieldset" bind:ref />
52
+ <ElementOrComponent {ourProps} {theirProps} {slot} defaultTag={DEFAULT_FIELDSET_TAG} name="Fieldset" bind:element />
@@ -1,34 +1,9 @@
1
- import type { ElementType, Props } from "../utils/types.js";
2
- declare let DEFAULT_FIELDSET_TAG: "fieldset";
1
+ import type { Props } from "../utils/types.js";
2
+ declare const DEFAULT_FIELDSET_TAG: "fieldset";
3
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, {
4
+ export type FieldsetProps = Props<typeof DEFAULT_FIELDSET_TAG, FieldsetRenderPropArg, {
5
+ element?: HTMLElement;
6
6
  disabled?: boolean;
7
7
  }>;
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>>;
8
+ declare const Fieldset: import("svelte").Component<FieldsetProps, {}, "element">;
34
9
  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,18 @@
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
42
  type FocusTrapRenderPropArg = {}
43
43
  type FocusTrapPropsWeControl = never
44
44
 
45
- export type FocusTrapProps<TTag extends ElementType = typeof DEFAULT_FOCUS_TRAP_TAG> = Props<
46
- TTag,
45
+ export type FocusTrapProps = Props<
46
+ typeof DEFAULT_FOCUS_TRAP_TAG,
47
47
  FocusTrapRenderPropArg,
48
- FocusTrapPropsWeControl,
49
48
  {
49
+ element?: HTMLElement
50
50
  initialFocus?: HTMLElement
51
51
  // A fallback element to focus, but this element will be skipped when tabbing around. This is
52
52
  // only done for focusing a fallback parent container (e.g.: A `Dialog`, but you want to tab
@@ -293,10 +293,10 @@
293
293
  }
294
294
  </script>
295
295
 
296
- <script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_FOCUS_TRAP_TAG">
296
+ <script lang="ts">
297
297
  let container = $state<HTMLElement | null>(null)
298
298
  let {
299
- ref = $bindable(),
299
+ element = $bindable(),
300
300
  initialFocus,
301
301
  initialFocusFallback,
302
302
  containers,
@@ -305,13 +305,13 @@
305
305
  FocusTrapFeatures.FocusLock |
306
306
  FocusTrapFeatures.RestoreFocus,
307
307
  ...theirProps
308
- }: { as?: TTag } & FocusTrapProps<TTag> = $props()
308
+ }: FocusTrapProps = $props()
309
309
 
310
310
  /*if (!useServerHandoffComplete()) {
311
311
  features = FocusTrapFeatures.None
312
312
  }*/
313
313
 
314
- const ownerDocument = $derived(getOwnerDocument(ref))
314
+ const ownerDocument = $derived(getOwnerDocument(element))
315
315
 
316
316
  useRestoreFocus({
317
317
  get features() {
@@ -441,21 +441,17 @@
441
441
  </script>
442
442
 
443
443
  {#if tabLockEnabled}
444
- <Hidden
445
- as="button"
446
- type="button"
447
- data-headlessui-focus-guard
448
- onfocus={handleFocus}
449
- features={HiddenFeatures.Focusable}
450
- />
444
+ <Hidden asChild features={HiddenFeatures.Focusable}>
445
+ {#snippet children({ props })}
446
+ <button {...props} type="button" data-headlessui-focus-guard onfocus={handleFocus}>&zwnj;</button>
447
+ {/snippet}
448
+ </Hidden>
451
449
  {/if}
452
- <ElementOrComponent {ourProps} {theirProps} defaultTag={DEFAULT_FOCUS_TRAP_TAG} name="FocusTrap" bind:ref />
450
+ <ElementOrComponent {ourProps} {theirProps} defaultTag={DEFAULT_FOCUS_TRAP_TAG} name="FocusTrap" bind:element />
453
451
  {#if tabLockEnabled}
454
- <Hidden
455
- as="button"
456
- type="button"
457
- data-headlessui-focus-guard
458
- onfocus={handleFocus}
459
- features={HiddenFeatures.Focusable}
460
- />
452
+ <Hidden asChild features={HiddenFeatures.Focusable}>
453
+ {#snippet children({ props })}
454
+ <button {...props} type="button" data-headlessui-focus-guard onfocus={handleFocus}>&zwnj;</button>
455
+ {/snippet}
456
+ </Hidden>
461
457
  {/if}
@@ -1,43 +1,15 @@
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
6
  type FocusTrapRenderPropArg = {};
7
- type FocusTrapPropsWeControl = never;
8
- export type FocusTrapProps<TTag extends ElementType = typeof DEFAULT_FOCUS_TRAP_TAG> = Props<TTag, FocusTrapRenderPropArg, FocusTrapPropsWeControl, {
7
+ export type FocusTrapProps = Props<typeof DEFAULT_FOCUS_TRAP_TAG, FocusTrapRenderPropArg, {
8
+ element?: HTMLElement;
9
9
  initialFocus?: HTMLElement;
10
10
  initialFocusFallback?: HTMLElement;
11
11
  features?: FocusTrapFeatures;
12
12
  containers?: Containers;
13
13
  }>;
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>>;
14
+ declare const FocusTrap: import("svelte").Component<FocusTrapProps, {}, "element">;
43
15
  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,5 +1,6 @@
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
 
@@ -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,4 +1,4 @@
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
3
  type InputRenderPropArg = {
4
4
  disabled: boolean;
@@ -7,41 +7,28 @@ type InputRenderPropArg = {
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;
@@ -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,7 +1,8 @@
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
 
@@ -9,28 +10,21 @@
9
10
 
10
11
  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 />
@@ -1,36 +1,11 @@
1
- import type { ElementType, Props } from "../utils/types.js";
1
+ import type { Props } from "../utils/types.js";
2
2
  import { HiddenFeatures } from "./HiddenFeatures.js";
3
3
  export * from "./HiddenFeatures.js";
4
4
  declare const DEFAULT_VISUALLY_HIDDEN_TAG: "span";
5
5
  type HiddenRenderPropArg = {};
6
- type HiddenPropsWeControl = never;
7
- export type HiddenProps<TTag extends ElementType = typeof DEFAULT_VISUALLY_HIDDEN_TAG> = Props<TTag, HiddenRenderPropArg, HiddenPropsWeControl, {
6
+ export type HiddenProps = Props<typeof DEFAULT_VISUALLY_HIDDEN_TAG, HiddenRenderPropArg, {
7
+ element?: HTMLElement;
8
8
  features?: HiddenFeatures;
9
9
  }>;
10
- declare class __sveltets_Render<TTag extends ElementType = typeof DEFAULT_VISUALLY_HIDDEN_TAG> {
11
- props(): {
12
- as?: TTag | undefined;
13
- } & (Exclude<keyof import("../utils/types.js").PropsOf<TTag>, ("slot" | "as" | "children" | "class" | "ref") | "features"> extends infer T extends keyof import("../utils/types.js").PropsOf<TTag> ? { [P in T]: import("../utils/types.js").PropsOf<TTag>[P]; } : never) & {
14
- children?: import("svelte").Snippet<[{
15
- props?: Record<string, any>;
16
- }]> | undefined;
17
- class?: string | ((bag: HiddenRenderPropArg) => string) | null | undefined;
18
- ref?: HTMLElement;
19
- } & {
20
- features?: HiddenFeatures;
21
- };
22
- events(): {};
23
- slots(): {};
24
- bindings(): "ref";
25
- exports(): {};
26
- }
27
- interface $$IsomorphicComponent {
28
- new <TTag extends ElementType = typeof DEFAULT_VISUALLY_HIDDEN_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']>> & {
29
- $$bindings?: ReturnType<__sveltets_Render<TTag>['bindings']>;
30
- } & ReturnType<__sveltets_Render<TTag>['exports']>;
31
- <TTag extends ElementType = typeof DEFAULT_VISUALLY_HIDDEN_TAG>(internal: unknown, props: ReturnType<__sveltets_Render<TTag>['props']> & {}): ReturnType<__sveltets_Render<TTag>['exports']>;
32
- z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
33
- }
34
- declare const Hidden: $$IsomorphicComponent;
35
- type Hidden<TTag extends ElementType = typeof DEFAULT_VISUALLY_HIDDEN_TAG> = InstanceType<typeof Hidden<TTag>>;
10
+ declare const Hidden: import("svelte").Component<HiddenProps, {}, "element">;
36
11
  export default Hidden;
@@ -94,5 +94,5 @@
94
94
 
95
95
  {#if children}{@render children()}{/if}
96
96
  {#if resolvedMainTreeNode === null}
97
- <Hidden features={HiddenFeatures.Hidden} bind:ref={el} />
97
+ <Hidden features={HiddenFeatures.Hidden} bind:element={el} />
98
98
  {/if}