@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.
- package/dist/button/Button.svelte +8 -9
- package/dist/button/Button.svelte.d.ts +4 -31
- package/dist/checkbox/Checkbox.svelte +14 -11
- package/dist/checkbox/Checkbox.svelte.d.ts +14 -31
- package/dist/close-button/CloseButton.svelte +4 -7
- package/dist/close-button/CloseButton.svelte.d.ts +2 -43
- package/dist/data-interactive/DataInteractive.svelte +5 -19
- package/dist/data-interactive/DataInteractive.svelte.d.ts +7 -29
- package/dist/description/Description.svelte +15 -12
- package/dist/description/Description.svelte.d.ts +7 -27
- package/dist/dialog/Dialog.svelte +34 -32
- package/dist/dialog/Dialog.svelte.d.ts +4 -41
- package/dist/dialog/DialogBackdrop.svelte +10 -10
- package/dist/dialog/DialogBackdrop.svelte.d.ts +4 -28
- package/dist/dialog/DialogPanel.svelte +18 -10
- package/dist/dialog/DialogPanel.svelte.d.ts +4 -29
- package/dist/dialog/DialogTitle.svelte +19 -7
- package/dist/dialog/DialogTitle.svelte.d.ts +6 -26
- package/dist/field/Field.svelte +9 -15
- package/dist/field/Field.svelte.d.ts +4 -29
- package/dist/fieldset/Fieldset.svelte +10 -13
- package/dist/fieldset/Fieldset.svelte.d.ts +5 -30
- package/dist/focus-trap/FocusTrap.svelte +20 -24
- package/dist/focus-trap/FocusTrap.svelte.d.ts +5 -33
- package/dist/hooks/use-inert-others.svelte.js +10 -10
- package/dist/hooks/use-resolve-button-type.svelte.js +0 -1
- package/dist/input/Input.svelte +19 -9
- package/dist/input/Input.svelte.d.ts +13 -26
- package/dist/internal/FocusSentinel.svelte +33 -32
- package/dist/internal/FormResolver.svelte +5 -1
- package/dist/internal/Hidden.svelte +9 -23
- package/dist/internal/Hidden.svelte.d.ts +4 -29
- package/dist/internal/MainTreeProvider.svelte +1 -1
- package/dist/label/Label.svelte +19 -13
- package/dist/label/Label.svelte.d.ts +7 -31
- package/dist/legend/Legend.svelte +20 -6
- package/dist/legend/Legend.svelte.d.ts +4 -3
- package/dist/listbox/Listbox.svelte +6 -17
- package/dist/listbox/Listbox.svelte.d.ts +11 -34
- package/dist/listbox/ListboxButton.svelte +14 -13
- package/dist/listbox/ListboxButton.svelte.d.ts +5 -31
- package/dist/listbox/ListboxOption.svelte +15 -15
- package/dist/listbox/ListboxOption.svelte.d.ts +12 -25
- package/dist/listbox/ListboxOptions.svelte +13 -11
- package/dist/listbox/ListboxOptions.svelte.d.ts +4 -37
- package/dist/listbox/ListboxSelectedOption.svelte +15 -17
- package/dist/listbox/ListboxSelectedOption.svelte.d.ts +8 -32
- package/dist/menu/Menu.svelte +5 -7
- package/dist/menu/Menu.svelte.d.ts +3 -30
- package/dist/menu/MenuButton.svelte +12 -12
- package/dist/menu/MenuButton.svelte.d.ts +4 -33
- package/dist/menu/MenuHeading.svelte +10 -9
- package/dist/menu/MenuHeading.svelte.d.ts +4 -30
- package/dist/menu/MenuItem.svelte +12 -12
- package/dist/menu/MenuItem.svelte.d.ts +5 -31
- package/dist/menu/MenuItems.svelte +12 -13
- package/dist/menu/MenuItems.svelte.d.ts +4 -37
- package/dist/menu/MenuSection.svelte +9 -8
- package/dist/menu/MenuSection.svelte.d.ts +5 -28
- package/dist/menu/MenuSeparator.svelte +9 -7
- package/dist/menu/MenuSeparator.svelte.d.ts +5 -27
- package/dist/popover/Popover.svelte +8 -8
- package/dist/popover/Popover.svelte.d.ts +4 -29
- package/dist/popover/PopoverBackdrop.svelte +15 -12
- package/dist/popover/PopoverBackdrop.svelte.d.ts +6 -33
- package/dist/popover/PopoverButton.svelte +34 -34
- package/dist/popover/PopoverButton.svelte.d.ts +6 -28
- package/dist/popover/PopoverGroup.svelte +14 -13
- package/dist/popover/PopoverGroup.svelte.d.ts +5 -27
- package/dist/popover/PopoverPanel.svelte +46 -41
- package/dist/popover/PopoverPanel.svelte.d.ts +5 -35
- package/dist/popover/index.d.ts +1 -1
- package/dist/portal/InternalPortal.svelte +17 -16
- package/dist/portal/InternalPortal.svelte.d.ts +4 -29
- package/dist/portal/Portal.svelte +7 -6
- package/dist/portal/Portal.svelte.d.ts +2 -18
- package/dist/portal/PortalGroup.svelte +5 -13
- package/dist/portal/PortalGroup.svelte.d.ts +3 -30
- package/dist/select/Select.svelte +10 -9
- package/dist/select/Select.svelte.d.ts +5 -31
- package/dist/switch/Switch.svelte +13 -12
- package/dist/switch/Switch.svelte.d.ts +5 -37
- package/dist/switch/SwitchGroup.svelte +5 -5
- package/dist/switch/SwitchGroup.svelte.d.ts +7 -27
- package/dist/tabs/Tab.svelte +12 -12
- package/dist/tabs/Tab.svelte.d.ts +4 -31
- package/dist/tabs/TabGroup.svelte +8 -8
- package/dist/tabs/TabGroup.svelte.d.ts +4 -33
- package/dist/tabs/TabList.svelte +7 -8
- package/dist/tabs/TabList.svelte.d.ts +5 -27
- package/dist/tabs/TabPanel.svelte +11 -11
- package/dist/tabs/TabPanel.svelte.d.ts +4 -33
- package/dist/tabs/TabPanels.svelte +5 -5
- package/dist/tabs/TabPanels.svelte.d.ts +5 -26
- package/dist/textarea/Textarea.svelte +12 -10
- package/dist/textarea/Textarea.svelte.d.ts +13 -26
- package/dist/transition/InternalTransitionChild.svelte +19 -12
- package/dist/transition/InternalTransitionChild.svelte.d.ts +3 -32
- package/dist/transition/Transition.svelte +12 -21
- package/dist/transition/Transition.svelte.d.ts +3 -35
- package/dist/transition/TransitionChild.svelte +9 -10
- package/dist/transition/TransitionChild.svelte.d.ts +8 -34
- package/dist/transition/context.svelte.js +7 -7
- package/dist/utils/ElementOrComponent.svelte +56 -15
- package/dist/utils/ElementOrComponent.svelte.d.ts +30 -23
- package/dist/utils/state.js +4 -4
- package/dist/utils/types.d.ts +12 -9
- package/package.json +12 -12
- package/dist/combobox/Combobox.svelte +0 -53
- package/dist/combobox/Combobox.svelte.d.ts +0 -50
- package/dist/utils/Generic.svelte +0 -57
- package/dist/utils/Generic.svelte.d.ts +0 -31
- package/dist/utils/alternative-types.d.ts +0 -20
- package/dist/utils/alternative-types.js +0 -1
|
@@ -1,31 +1,28 @@
|
|
|
1
1
|
<script lang="ts" module>
|
|
2
|
-
import type {
|
|
3
|
-
|
|
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
|
|
9
|
-
|
|
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"
|
|
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
|
-
|
|
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:
|
|
52
|
+
<ElementOrComponent {ourProps} {theirProps} {slot} defaultTag={DEFAULT_FIELDSET_TAG} name="Fieldset" bind:element />
|
|
@@ -1,34 +1,9 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
declare
|
|
1
|
+
import type { Props } from "../utils/types.js";
|
|
2
|
+
declare const DEFAULT_FIELDSET_TAG: "fieldset";
|
|
3
3
|
type FieldsetRenderPropArg = {};
|
|
4
|
-
type
|
|
5
|
-
|
|
4
|
+
export type FieldsetProps = Props<typeof DEFAULT_FIELDSET_TAG, FieldsetRenderPropArg, {
|
|
5
|
+
element?: HTMLElement;
|
|
6
6
|
disabled?: boolean;
|
|
7
7
|
}>;
|
|
8
|
-
declare
|
|
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 {
|
|
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
|
-
|
|
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
|
|
46
|
-
|
|
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"
|
|
296
|
+
<script lang="ts">
|
|
297
297
|
let container = $state<HTMLElement | null>(null)
|
|
298
298
|
let {
|
|
299
|
-
|
|
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
|
-
}:
|
|
308
|
+
}: FocusTrapProps = $props()
|
|
309
309
|
|
|
310
310
|
/*if (!useServerHandoffComplete()) {
|
|
311
311
|
features = FocusTrapFeatures.None
|
|
312
312
|
}*/
|
|
313
313
|
|
|
314
|
-
const ownerDocument = $derived(getOwnerDocument(
|
|
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
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
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}>‌</button>
|
|
447
|
+
{/snippet}
|
|
448
|
+
</Hidden>
|
|
451
449
|
{/if}
|
|
452
|
-
<ElementOrComponent {ourProps} {theirProps} defaultTag={DEFAULT_FOCUS_TRAP_TAG} name="FocusTrap" bind:
|
|
450
|
+
<ElementOrComponent {ourProps} {theirProps} defaultTag={DEFAULT_FOCUS_TRAP_TAG} name="FocusTrap" bind:element />
|
|
453
451
|
{#if tabLockEnabled}
|
|
454
|
-
<Hidden
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
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}>‌</button>
|
|
455
|
+
{/snippet}
|
|
456
|
+
</Hidden>
|
|
461
457
|
{/if}
|
|
@@ -1,43 +1,15 @@
|
|
|
1
|
-
import type {
|
|
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
|
|
4
|
+
declare const DEFAULT_FOCUS_TRAP_TAG: "div";
|
|
5
5
|
export * from "./FocusTrapFeatures.js";
|
|
6
6
|
type FocusTrapRenderPropArg = {};
|
|
7
|
-
type
|
|
8
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
82
|
+
const d = disposables();
|
|
83
83
|
// Mark all disallowed elements as inert
|
|
84
|
-
for (
|
|
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
|
-
|
|
91
|
-
for (
|
|
90
|
+
const allowedElements = allowed ?? [];
|
|
91
|
+
for (const element of allowedElements) {
|
|
92
92
|
if (!element)
|
|
93
93
|
continue;
|
|
94
|
-
|
|
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 (
|
|
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)))
|
package/dist/input/Input.svelte
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
<script lang="ts" module>
|
|
2
|
-
import type {
|
|
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<
|
|
16
|
-
|
|
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="
|
|
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
|
-
|
|
46
|
+
element = $bindable(),
|
|
45
47
|
value = $bindable(),
|
|
46
|
-
id =
|
|
48
|
+
id = providedId || `headlessui-input-${internalId}`,
|
|
47
49
|
disabled: theirDisabled = false,
|
|
48
50
|
autofocus = false,
|
|
49
51
|
invalid = false,
|
|
50
52
|
...theirProps
|
|
51
|
-
}:
|
|
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
|
|
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 {
|
|
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
|
|
11
|
-
|
|
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<
|
|
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(): "
|
|
22
|
+
bindings(): "element" | "value";
|
|
36
23
|
exports(): {};
|
|
37
24
|
}
|
|
38
25
|
interface $$IsomorphicComponent {
|
|
39
|
-
new <
|
|
40
|
-
$$bindings?: ReturnType<__sveltets_Render<
|
|
41
|
-
} & ReturnType<__sveltets_Render<
|
|
42
|
-
<
|
|
43
|
-
z_$$bindings?: ReturnType<__sveltets_Render<any
|
|
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<
|
|
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
|
-
{
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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}>‌</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}
|
|
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 {
|
|
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
|
|
13
|
-
|
|
13
|
+
export type HiddenProps = Props<
|
|
14
|
+
typeof DEFAULT_VISUALLY_HIDDEN_TAG,
|
|
14
15
|
HiddenRenderPropArg,
|
|
15
|
-
|
|
16
|
-
{ features?: HiddenFeatures }
|
|
16
|
+
{ element?: HTMLElement; features?: HiddenFeatures }
|
|
17
17
|
>
|
|
18
18
|
</script>
|
|
19
19
|
|
|
20
|
-
<script lang="ts"
|
|
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"
|
|
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 {
|
|
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
|
|
7
|
-
|
|
6
|
+
export type HiddenProps = Props<typeof DEFAULT_VISUALLY_HIDDEN_TAG, HiddenRenderPropArg, {
|
|
7
|
+
element?: HTMLElement;
|
|
8
8
|
features?: HiddenFeatures;
|
|
9
9
|
}>;
|
|
10
|
-
declare
|
|
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;
|