@pzerelles/headlessui-svelte 2.1.2-next.2 → 2.1.2-next.4
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 +84 -54
- package/dist/checkbox/Checkbox.svelte +174 -120
- package/dist/close-button/CloseButton.svelte +12 -6
- package/dist/combobox/Combobox.svelte +50 -3
- package/dist/data-interactive/DataInteractive.svelte +57 -29
- package/dist/description/Description.svelte +32 -21
- package/dist/dialog/Dialog.svelte +69 -34
- package/dist/dialog/DialogBackdrop.svelte +29 -12
- package/dist/dialog/DialogPanel.svelte +49 -26
- package/dist/dialog/DialogTitle.svelte +38 -23
- package/dist/dialog/InternalDialog.svelte +263 -202
- package/dist/field/Field.svelte +49 -26
- package/dist/fieldset/Fieldset.svelte +50 -29
- package/dist/focus-trap/FocusTrap.svelte +436 -290
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/input/Input.svelte +85 -53
- package/dist/internal/FocusSentinel.svelte +16 -8
- package/dist/internal/ForcePortalRoot.svelte +7 -3
- package/dist/internal/FormFields.svelte +31 -20
- package/dist/internal/FormResolver.svelte +20 -15
- package/dist/internal/Hidden.svelte +44 -27
- package/dist/internal/Hidden.svelte.d.ts +2 -5
- package/dist/internal/HiddenFeatures.d.ts +5 -0
- package/dist/internal/HiddenFeatures.js +9 -0
- package/dist/internal/HoistFormFields.svelte +7 -4
- package/dist/internal/MainTreeProvider.svelte +89 -36
- package/dist/internal/Portal.svelte +18 -14
- package/dist/label/Label.svelte +91 -57
- package/dist/legend/Legend.svelte +18 -3
- package/dist/listbox/Listbox.svelte +600 -409
- package/dist/listbox/ListboxButton.svelte +176 -127
- package/dist/listbox/ListboxOption.svelte +166 -125
- package/dist/listbox/ListboxOptions.svelte +340 -244
- package/dist/listbox/ListboxSelectedOption.svelte +38 -15
- package/dist/menu/Menu.svelte +307 -218
- package/dist/menu/MenuButton.svelte +157 -115
- package/dist/menu/MenuHeading.svelte +34 -14
- package/dist/menu/MenuItem.svelte +145 -107
- package/dist/menu/MenuItems.svelte +298 -224
- package/dist/menu/MenuSection.svelte +26 -9
- package/dist/menu/MenuSeparator.svelte +20 -4
- package/dist/portal/InternalPortal.svelte +141 -85
- package/dist/portal/Portal.svelte +5 -2
- package/dist/portal/PortalGroup.svelte +30 -9
- package/dist/switch/Switch.svelte +179 -122
- package/dist/switch/Switch.svelte.d.ts +4 -4
- package/dist/switch/SwitchGroup.svelte +44 -31
- package/dist/tabs/Tab.svelte +195 -143
- package/dist/tabs/TabGroup.svelte +292 -205
- package/dist/tabs/TabList.svelte +31 -11
- package/dist/tabs/TabPanel.svelte +68 -43
- package/dist/tabs/TabPanels.svelte +18 -7
- package/dist/textarea/Textarea.svelte +97 -0
- package/dist/textarea/Textarea.svelte.d.ts +47 -0
- package/dist/textarea/index.d.ts +1 -0
- package/dist/textarea/index.js +1 -0
- package/dist/transition/InternalTransitionChild.svelte +259 -170
- package/dist/transition/Transition.svelte +96 -66
- package/dist/transition/TransitionChild.svelte +31 -11
- package/dist/utils/ElementOrComponent.svelte +44 -23
- package/dist/utils/Generic.svelte +29 -17
- package/dist/utils/StableCollection.svelte +54 -36
- package/package.json +10 -10
package/dist/label/Label.svelte
CHANGED
|
@@ -1,65 +1,99 @@
|
|
|
1
|
-
<script lang="ts" module>
|
|
2
|
-
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import type { ElementType, Props, PropsOf } from "../utils/types.js"
|
|
3
|
+
|
|
4
|
+
let DEFAULT_LABEL_TAG = "label" as const
|
|
3
5
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import { stateFromSlot } from "../utils/state.js";
|
|
8
|
-
import ElementOrComponent from "../utils/ElementOrComponent.svelte";
|
|
9
|
-
import { useLabelContext } from "./context.svelte.js";
|
|
10
|
-
const internalId = htmlid();
|
|
11
|
-
const context = useLabelContext();
|
|
12
|
-
const providedHtmlFor = getIdContext();
|
|
13
|
-
const providedDisabled = useDisabled();
|
|
14
|
-
let {
|
|
15
|
-
ref = $bindable(),
|
|
16
|
-
id = `headlessui-label-${internalId}`,
|
|
17
|
-
htmlFor = providedHtmlFor,
|
|
18
|
-
passive = false,
|
|
19
|
-
...theirOriginalProps
|
|
20
|
-
} = $props();
|
|
21
|
-
onMount(() => {
|
|
22
|
-
context.register(id);
|
|
23
|
-
});
|
|
24
|
-
let handleClick = (e) => {
|
|
25
|
-
let current = e.currentTarget;
|
|
26
|
-
if (current instanceof HTMLLabelElement) {
|
|
27
|
-
e.preventDefault();
|
|
6
|
+
export type LabelProps<TTag extends ElementType = typeof DEFAULT_LABEL_TAG> = Props<TTag> & {
|
|
7
|
+
passive?: boolean
|
|
8
|
+
htmlFor?: string
|
|
28
9
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
10
|
+
</script>
|
|
11
|
+
|
|
12
|
+
<script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_LABEL_TAG">
|
|
13
|
+
import { onMount } from "svelte"
|
|
14
|
+
import { getIdContext, htmlid } from "../utils/id.js"
|
|
15
|
+
import { useDisabled } from "../hooks/use-disabled.js"
|
|
16
|
+
import { stateFromSlot } from "../utils/state.js"
|
|
17
|
+
import ElementOrComponent from "../utils/ElementOrComponent.svelte"
|
|
18
|
+
import { useLabelContext } from "./context.svelte.js"
|
|
19
|
+
|
|
20
|
+
const internalId = htmlid()
|
|
21
|
+
const context = useLabelContext()
|
|
22
|
+
const providedHtmlFor = getIdContext()
|
|
23
|
+
const providedDisabled = useDisabled()
|
|
24
|
+
|
|
25
|
+
let {
|
|
26
|
+
ref = $bindable(),
|
|
27
|
+
id = `headlessui-label-${internalId}` as PropsOf<TTag>["id"],
|
|
28
|
+
htmlFor = providedHtmlFor,
|
|
29
|
+
passive = false,
|
|
30
|
+
...theirOriginalProps
|
|
31
|
+
}: { as?: TTag } & LabelProps<TTag> = $props()
|
|
32
|
+
|
|
33
|
+
onMount(() => {
|
|
34
|
+
context.register(id)
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
let handleClick = (e: MouseEvent) => {
|
|
38
|
+
let current = e.currentTarget
|
|
39
|
+
|
|
40
|
+
// Labels connected to 'real' controls will already click the element. But we don't know that
|
|
41
|
+
// ahead of time. This will prevent the default click, such that only a single click happens
|
|
42
|
+
// instead of two. Otherwise this results in a visual no-op.
|
|
43
|
+
if (current instanceof HTMLLabelElement) {
|
|
44
|
+
e.preventDefault()
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (current instanceof HTMLLabelElement) {
|
|
48
|
+
let target = document.getElementById(current.getAttribute("htmlFor") ?? "")
|
|
49
|
+
if (target) {
|
|
50
|
+
// Bail if the target element is disabled
|
|
51
|
+
let actuallyDisabled = target.getAttribute("disabled")
|
|
52
|
+
if (actuallyDisabled === "true" || actuallyDisabled === "") {
|
|
53
|
+
return
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
let ariaDisabled = target.getAttribute("aria-disabled")
|
|
57
|
+
if (ariaDisabled === "true" || ariaDisabled === "") {
|
|
58
|
+
return
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Ensure we click the element this label is bound to. This is necessary for elements that
|
|
62
|
+
// immediately require state changes, e.g.: Radio & Checkbox inputs need to be checked (or
|
|
63
|
+
// unchecked).
|
|
64
|
+
if (
|
|
65
|
+
(target instanceof HTMLInputElement && (target.type === "radio" || target.type === "checkbox")) ||
|
|
66
|
+
target.role === "radio" ||
|
|
67
|
+
target.role === "checkbox" ||
|
|
68
|
+
target.role === "switch"
|
|
69
|
+
) {
|
|
70
|
+
target.click()
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Move focus to the element, this allows you to start using keyboard shortcuts since the
|
|
74
|
+
// bound element is now focused.
|
|
75
|
+
target.focus({ preventScroll: true })
|
|
42
76
|
}
|
|
43
|
-
target.focus({ preventScroll: true });
|
|
44
77
|
}
|
|
45
78
|
}
|
|
46
|
-
|
|
47
|
-
const disabled = $derived(providedDisabled.value ?? false)
|
|
48
|
-
const slot = $derived({ disabled })
|
|
49
|
-
const ourProps = $derived({
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
79
|
+
|
|
80
|
+
const disabled = $derived(providedDisabled.value ?? false)
|
|
81
|
+
const slot = $derived({ disabled })
|
|
82
|
+
const ourProps = $derived({
|
|
83
|
+
id,
|
|
84
|
+
htmlFor: passive ? undefined : htmlFor,
|
|
85
|
+
onclick: passive ? undefined : handleClick,
|
|
86
|
+
...stateFromSlot(slot),
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
const theirProps = $derived.by(() => {
|
|
90
|
+
if (passive) {
|
|
91
|
+
const { onclick: _, ...props } = theirOriginalProps
|
|
92
|
+
return props
|
|
93
|
+
} else {
|
|
94
|
+
return theirOriginalProps
|
|
95
|
+
}
|
|
96
|
+
})
|
|
63
97
|
</script>
|
|
64
98
|
|
|
65
99
|
<ElementOrComponent
|
|
@@ -1,8 +1,23 @@
|
|
|
1
|
-
<script lang="ts" module>
|
|
2
|
-
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import { Label, type LabelProps } from "../index.js"
|
|
3
|
+
import type { ElementType, Props } from "../utils/types.js"
|
|
4
|
+
import type { Component } from "svelte"
|
|
5
|
+
|
|
6
|
+
const DEFAULT_LEGEND_TAG = Label as Component<LabelProps, any>
|
|
7
|
+
|
|
8
|
+
type LegendRenderPropArg = {}
|
|
9
|
+
type LegendPropsWeControl = never
|
|
10
|
+
|
|
11
|
+
export type LegendProps<TTag extends ElementType = typeof DEFAULT_LEGEND_TAG> = Props<
|
|
12
|
+
TTag,
|
|
13
|
+
LegendRenderPropArg,
|
|
14
|
+
LegendPropsWeControl,
|
|
15
|
+
{}
|
|
16
|
+
>
|
|
3
17
|
</script>
|
|
4
18
|
|
|
5
|
-
<script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_LEGEND_TAG">
|
|
19
|
+
<script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_LEGEND_TAG">
|
|
20
|
+
let { ...props }: { as?: TTag } & LegendProps<TTag> = $props()
|
|
6
21
|
</script>
|
|
7
22
|
|
|
8
23
|
<Label as="div" {...props} />
|