@pzerelles/headlessui-svelte 2.1.2-next.7 → 2.1.2-next.9
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 +54 -84
- package/dist/checkbox/Checkbox.svelte +120 -174
- package/dist/checkbox/Checkbox.svelte.d.ts +4 -6
- package/dist/close-button/CloseButton.svelte +6 -12
- package/dist/combobox/Combobox.svelte +3 -50
- package/dist/data-interactive/DataInteractive.svelte +29 -57
- package/dist/description/Description.svelte +21 -32
- package/dist/dialog/Dialog.svelte +34 -69
- package/dist/dialog/DialogBackdrop.svelte +12 -29
- package/dist/dialog/DialogPanel.svelte +26 -49
- package/dist/dialog/DialogTitle.svelte +23 -38
- package/dist/dialog/InternalDialog.svelte +202 -263
- package/dist/field/Field.svelte +25 -49
- package/dist/fieldset/Fieldset.svelte +29 -50
- package/dist/focus-trap/FocusTrap.svelte +283 -419
- package/dist/input/Input.svelte +53 -84
- package/dist/internal/FocusSentinel.svelte +8 -16
- package/dist/internal/ForcePortalRoot.svelte +3 -7
- package/dist/internal/FormFields.svelte +20 -31
- package/dist/internal/FormResolver.svelte +15 -20
- package/dist/internal/Hidden.svelte +23 -44
- package/dist/internal/HoistFormFields.svelte +4 -7
- package/dist/internal/MainTreeProvider.svelte +36 -89
- package/dist/internal/Portal.svelte +14 -18
- package/dist/label/Label.svelte +58 -91
- package/dist/legend/Legend.svelte +3 -18
- package/dist/listbox/Listbox.svelte +396 -588
- package/dist/listbox/ListboxButton.svelte +127 -176
- package/dist/listbox/ListboxButton.svelte.d.ts +4 -6
- package/dist/listbox/ListboxOption.svelte +125 -166
- package/dist/listbox/ListboxOptions.svelte +244 -340
- package/dist/listbox/ListboxSelectedOption.svelte +15 -38
- package/dist/menu/Menu.svelte +218 -307
- package/dist/menu/MenuButton.svelte +115 -157
- package/dist/menu/MenuHeading.svelte +14 -34
- package/dist/menu/MenuItem.svelte +107 -145
- package/dist/menu/MenuItems.svelte +224 -298
- package/dist/menu/MenuSection.svelte +9 -26
- package/dist/menu/MenuSeparator.svelte +4 -20
- package/dist/portal/InternalPortal.svelte +85 -141
- package/dist/portal/Portal.svelte +2 -5
- package/dist/portal/PortalGroup.svelte +9 -30
- package/dist/switch/Switch.svelte +132 -179
- package/dist/switch/SwitchGroup.svelte +31 -44
- package/dist/tabs/Tab.svelte +143 -195
- package/dist/tabs/TabGroup.svelte +205 -292
- package/dist/tabs/TabList.svelte +11 -31
- package/dist/tabs/TabPanel.svelte +43 -68
- package/dist/tabs/TabPanels.svelte +7 -18
- package/dist/textarea/Textarea.svelte +53 -84
- package/dist/transition/InternalTransitionChild.svelte +170 -259
- package/dist/transition/Transition.svelte +66 -96
- package/dist/transition/TransitionChild.svelte +11 -31
- package/dist/utils/ElementOrComponent.svelte +23 -44
- package/dist/utils/Generic.svelte +17 -29
- package/dist/utils/StableCollection.svelte +36 -54
- package/dist/utils/id.d.ts +1 -1
- package/dist/utils/id.js +1 -1
- package/package.json +12 -12
- package/dist/internal/id.d.ts +0 -8
- package/dist/internal/id.js +0 -11
|
@@ -1,50 +1,37 @@
|
|
|
1
|
-
<script lang="ts" module>
|
|
2
|
-
import type { ElementType, Props } from "../utils/types.js"
|
|
3
|
-
|
|
4
|
-
const DEFAULT_GROUP_TAG = "svelte:fragment"
|
|
5
|
-
|
|
6
|
-
export type SwitchGroupProps<TTag extends ElementType = typeof DEFAULT_GROUP_TAG> = Props<TTag>
|
|
7
|
-
|
|
8
|
-
export type GroupContext = {
|
|
9
|
-
switchElement: HTMLElement | null
|
|
10
|
-
}
|
|
1
|
+
<script lang="ts" module>const DEFAULT_GROUP_TAG = "svelte:fragment";
|
|
11
2
|
</script>
|
|
12
3
|
|
|
13
|
-
<script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_GROUP_TAG">
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
get htmlFor() {
|
|
24
|
-
return switchElement?.id
|
|
25
|
-
},
|
|
26
|
-
onclick: (event: MouseEvent) => {
|
|
27
|
-
if (!switchElement) return
|
|
28
|
-
if (event.currentTarget instanceof HTMLLabelElement) {
|
|
29
|
-
event.preventDefault()
|
|
30
|
-
}
|
|
31
|
-
switchElement.click()
|
|
32
|
-
switchElement.focus({ preventScroll: true })
|
|
33
|
-
},
|
|
4
|
+
<script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_GROUP_TAG">import { setContext } from "svelte";
|
|
5
|
+
import { useLabels } from "../label/context.svelte.js";
|
|
6
|
+
import { useDescriptions } from "../description/context.svelte.js";
|
|
7
|
+
import ElementOrComponent from "../utils/ElementOrComponent.svelte";
|
|
8
|
+
let switchElement = $state(null);
|
|
9
|
+
useLabels({
|
|
10
|
+
name: "SwitchGroup",
|
|
11
|
+
props: {
|
|
12
|
+
get htmlFor() {
|
|
13
|
+
return switchElement?.id;
|
|
34
14
|
},
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
15
|
+
onclick: (event) => {
|
|
16
|
+
if (!switchElement) return;
|
|
17
|
+
if (event.currentTarget instanceof HTMLLabelElement) {
|
|
18
|
+
event.preventDefault();
|
|
19
|
+
}
|
|
20
|
+
switchElement.click();
|
|
21
|
+
switchElement.focus({ preventScroll: true });
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
useDescriptions();
|
|
26
|
+
setContext("GroupContext", {
|
|
27
|
+
get switchElement() {
|
|
28
|
+
return switchElement;
|
|
29
|
+
},
|
|
30
|
+
set switchElement(element) {
|
|
31
|
+
switchElement = element;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
let { ref = $bindable(), ...theirProps } = $props();
|
|
48
35
|
</script>
|
|
49
36
|
|
|
50
37
|
<ElementOrComponent {theirProps} defaultTag={DEFAULT_GROUP_TAG} name="SwitchGroup" bind:ref />
|
package/dist/tabs/Tab.svelte
CHANGED
|
@@ -1,208 +1,156 @@
|
|
|
1
|
-
<script lang="ts" module>
|
|
2
|
-
|
|
1
|
+
<script lang="ts" module>const DEFAULT_TAB_TAG = "button";
|
|
2
|
+
</script>
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
<script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_TAB_TAG">import { useId } from "../hooks/use-id.js";
|
|
5
|
+
import { useActions, useData } from "./TabGroup.svelte";
|
|
6
|
+
import { useStableCollectionIndex } from "../utils/StableCollection.svelte";
|
|
7
|
+
import { Focus, focusIn, FocusResult } from "../utils/focus-management.js";
|
|
8
|
+
import { getOwnerDocument } from "../utils/owner.js";
|
|
9
|
+
import { match } from "../utils/match.js";
|
|
10
|
+
import { microTask } from "../utils/microTask.js";
|
|
11
|
+
import { useActivePress } from "../hooks/use-active-press.svelte.js";
|
|
12
|
+
import { useFocusRing } from "../hooks/use-focus-ring.svelte.js";
|
|
13
|
+
import { useResolveButtonType } from "../hooks/use-resolve-button-type.svelte.js";
|
|
14
|
+
import { onMount } from "svelte";
|
|
15
|
+
import { useHover } from "../hooks/use-hover.svelte.js";
|
|
16
|
+
import { mergeProps } from "../utils/render.js";
|
|
17
|
+
import ElementOrComponent from "../utils/ElementOrComponent.svelte";
|
|
18
|
+
const internalId = useId();
|
|
19
|
+
let {
|
|
20
|
+
ref = $bindable(),
|
|
21
|
+
id = `headlessui-tabs-tab-${internalId}`,
|
|
22
|
+
disabled = false,
|
|
23
|
+
autofocus = false,
|
|
24
|
+
...theirProps
|
|
25
|
+
} = $props();
|
|
26
|
+
const data = useData("Tab");
|
|
27
|
+
const { orientation, activation, selectedIndex, tabs, panels } = $derived(data);
|
|
28
|
+
const actions = useActions("Tab");
|
|
29
|
+
const tabRef = $derived({ current: ref });
|
|
30
|
+
onMount(() => actions.registerTab(tabRef));
|
|
31
|
+
const mySSRIndex = useStableCollectionIndex("tabs");
|
|
32
|
+
const myIndex = $derived.by(() => {
|
|
33
|
+
const index = tabs.findIndex((tab) => tab === tabRef);
|
|
34
|
+
return index === -1 ? mySSRIndex : index;
|
|
35
|
+
});
|
|
36
|
+
const selected = $derived(myIndex === selectedIndex);
|
|
37
|
+
const activateUsing = $derived((cb) => {
|
|
38
|
+
let result = cb();
|
|
39
|
+
if (result === FocusResult.Success && activation === "auto") {
|
|
40
|
+
let newTab = getOwnerDocument(ref)?.activeElement;
|
|
41
|
+
let idx = data.tabs.findIndex((tab) => tab.current === newTab);
|
|
42
|
+
if (idx !== -1) actions.change(idx);
|
|
12
43
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
44
|
+
return result;
|
|
45
|
+
});
|
|
46
|
+
const handleKeyDown = (event) => {
|
|
47
|
+
let list = tabs.map((tab) => tab.current).filter(Boolean);
|
|
48
|
+
if (event.key === " " || event.key === "Enter") {
|
|
49
|
+
event.preventDefault();
|
|
50
|
+
event.stopPropagation();
|
|
51
|
+
actions.change(myIndex);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
switch (event.key) {
|
|
55
|
+
case "Home":
|
|
56
|
+
case "PageUp":
|
|
57
|
+
event.preventDefault();
|
|
58
|
+
event.stopPropagation();
|
|
59
|
+
return activateUsing(() => focusIn(list, Focus.First));
|
|
60
|
+
case "End":
|
|
61
|
+
case "PageDown":
|
|
62
|
+
event.preventDefault();
|
|
63
|
+
event.stopPropagation();
|
|
64
|
+
return activateUsing(() => focusIn(list, Focus.Last));
|
|
65
|
+
}
|
|
66
|
+
let result = activateUsing(() => {
|
|
67
|
+
return match(orientation, {
|
|
68
|
+
vertical() {
|
|
69
|
+
if (event.key === "ArrowUp") return focusIn(list, Focus.Previous | Focus.WrapAround);
|
|
70
|
+
if (event.key === "ArrowDown") return focusIn(list, Focus.Next | Focus.WrapAround);
|
|
71
|
+
return FocusResult.Error;
|
|
72
|
+
},
|
|
73
|
+
horizontal() {
|
|
74
|
+
if (event.key === "ArrowLeft") return focusIn(list, Focus.Previous | Focus.WrapAround);
|
|
75
|
+
if (event.key === "ArrowRight") return focusIn(list, Focus.Next | Focus.WrapAround);
|
|
76
|
+
return FocusResult.Error;
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
if (result === FocusResult.Success) {
|
|
81
|
+
return event.preventDefault();
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
let ready = $state(false);
|
|
85
|
+
const handleSelection = () => {
|
|
86
|
+
if (ready) return;
|
|
87
|
+
ready = true;
|
|
88
|
+
ref?.focus({ preventScroll: true });
|
|
89
|
+
actions.change(myIndex);
|
|
90
|
+
microTask(() => {
|
|
91
|
+
ready = false;
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
const handleMouseDown = (event) => {
|
|
95
|
+
event.preventDefault();
|
|
96
|
+
};
|
|
97
|
+
const { isHovered: hover, hoverProps } = $derived(
|
|
98
|
+
useHover({
|
|
99
|
+
get disabled() {
|
|
100
|
+
return disabled;
|
|
23
101
|
}
|
|
24
|
-
>
|
|
25
|
-
</script>
|
|
26
|
-
|
|
27
|
-
<script lang="ts" generics="TTag extends ElementType = typeof DEFAULT_TAB_TAG">
|
|
28
|
-
import { useId } from "../hooks/use-id.js"
|
|
29
|
-
import { useActions, useData } from "./TabGroup.svelte"
|
|
30
|
-
import { useStableCollectionIndex } from "../utils/StableCollection.svelte"
|
|
31
|
-
import { Focus, focusIn, FocusResult } from "../utils/focus-management.js"
|
|
32
|
-
import { getOwnerDocument } from "../utils/owner.js"
|
|
33
|
-
import { match } from "../utils/match.js"
|
|
34
|
-
import { microTask } from "../utils/microTask.js"
|
|
35
|
-
import { useActivePress } from "../hooks/use-active-press.svelte.js"
|
|
36
|
-
import { useFocusRing } from "../hooks/use-focus-ring.svelte.js"
|
|
37
|
-
import { useResolveButtonType } from "../hooks/use-resolve-button-type.svelte.js"
|
|
38
|
-
import type { MutableRefObject } from "../utils/ref.svelte.js"
|
|
39
|
-
import { onMount } from "svelte"
|
|
40
|
-
import { useHover } from "../hooks/use-hover.svelte.js"
|
|
41
|
-
import { mergeProps } from "../utils/render.js"
|
|
42
|
-
import ElementOrComponent from "../utils/ElementOrComponent.svelte"
|
|
43
|
-
|
|
44
|
-
const internalId = useId()
|
|
45
|
-
let {
|
|
46
|
-
ref = $bindable(),
|
|
47
|
-
id = `headlessui-tabs-tab-${internalId}`,
|
|
48
|
-
disabled = false,
|
|
49
|
-
autofocus = false,
|
|
50
|
-
...theirProps
|
|
51
|
-
}: { as?: TTag } & TabProps<TTag> = $props()
|
|
52
|
-
|
|
53
|
-
const data = useData("Tab")
|
|
54
|
-
const { orientation, activation, selectedIndex, tabs, panels } = $derived(data)
|
|
55
|
-
const actions = useActions("Tab")
|
|
56
|
-
|
|
57
|
-
const tabRef = $derived<MutableRefObject<HTMLElement | undefined>>({ current: ref })
|
|
58
|
-
|
|
59
|
-
onMount(() => actions.registerTab(tabRef))
|
|
60
|
-
|
|
61
|
-
const mySSRIndex = useStableCollectionIndex("tabs")
|
|
62
|
-
|
|
63
|
-
const myIndex = $derived.by(() => {
|
|
64
|
-
const index = tabs.findIndex((tab) => tab === tabRef)
|
|
65
|
-
return index === -1 ? mySSRIndex : index
|
|
66
102
|
})
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
let newTab = getOwnerDocument(ref)?.activeElement
|
|
73
|
-
let idx = data.tabs.findIndex((tab) => tab.current === newTab)
|
|
74
|
-
if (idx !== -1) actions.change(idx)
|
|
103
|
+
);
|
|
104
|
+
const { pressed: active, pressProps } = $derived(
|
|
105
|
+
useActivePress({
|
|
106
|
+
get disabled() {
|
|
107
|
+
return disabled;
|
|
75
108
|
}
|
|
76
|
-
return result
|
|
77
109
|
})
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
event.preventDefault()
|
|
84
|
-
event.stopPropagation()
|
|
85
|
-
|
|
86
|
-
actions.change(myIndex)
|
|
87
|
-
return
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
switch (event.key) {
|
|
91
|
-
case "Home":
|
|
92
|
-
case "PageUp":
|
|
93
|
-
event.preventDefault()
|
|
94
|
-
event.stopPropagation()
|
|
95
|
-
|
|
96
|
-
return activateUsing(() => focusIn(list, Focus.First))
|
|
97
|
-
|
|
98
|
-
case "End":
|
|
99
|
-
case "PageDown":
|
|
100
|
-
event.preventDefault()
|
|
101
|
-
event.stopPropagation()
|
|
102
|
-
|
|
103
|
-
return activateUsing(() => focusIn(list, Focus.Last))
|
|
110
|
+
);
|
|
111
|
+
const { isFocusVisible: focus, focusProps } = $derived(
|
|
112
|
+
useFocusRing({
|
|
113
|
+
get autofocus() {
|
|
114
|
+
return autofocus;
|
|
104
115
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
if (result === FocusResult.Success) {
|
|
122
|
-
return event.preventDefault()
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
let ready = $state(false)
|
|
127
|
-
const handleSelection = () => {
|
|
128
|
-
if (ready) return
|
|
129
|
-
ready = true
|
|
130
|
-
|
|
131
|
-
ref?.focus({ preventScroll: true })
|
|
132
|
-
actions.change(myIndex)
|
|
133
|
-
|
|
134
|
-
microTask(() => {
|
|
135
|
-
ready = false
|
|
136
|
-
})
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// This is important because we want to only focus the tab when it gets focus
|
|
140
|
-
// OR it finished the click event (mouseup). However, if you perform a `click`,
|
|
141
|
-
// then you will first get the `focus` and then get the `click` event.
|
|
142
|
-
const handleMouseDown = (event: MouseEvent) => {
|
|
143
|
-
event.preventDefault()
|
|
116
|
+
})
|
|
117
|
+
);
|
|
118
|
+
const slot = $derived({
|
|
119
|
+
selected,
|
|
120
|
+
hover,
|
|
121
|
+
active,
|
|
122
|
+
focus,
|
|
123
|
+
autofocus,
|
|
124
|
+
disabled
|
|
125
|
+
});
|
|
126
|
+
const resolvedType = useResolveButtonType({
|
|
127
|
+
get props() {
|
|
128
|
+
return { type: theirProps.type, as: theirProps.as };
|
|
129
|
+
},
|
|
130
|
+
get ref() {
|
|
131
|
+
return tabRef;
|
|
144
132
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
const { isFocusVisible: focus, focusProps } = $derived(
|
|
161
|
-
useFocusRing({
|
|
162
|
-
get autofocus() {
|
|
163
|
-
return autofocus
|
|
164
|
-
},
|
|
165
|
-
})
|
|
166
|
-
)
|
|
167
|
-
|
|
168
|
-
const slot = $derived({
|
|
169
|
-
selected,
|
|
170
|
-
hover,
|
|
171
|
-
active,
|
|
172
|
-
focus,
|
|
173
|
-
autofocus,
|
|
174
|
-
disabled,
|
|
175
|
-
} satisfies TabRenderPropArg)
|
|
176
|
-
|
|
177
|
-
const resolvedType = useResolveButtonType({
|
|
178
|
-
get props() {
|
|
179
|
-
return { type: theirProps.type, as: theirProps.as }
|
|
180
|
-
},
|
|
181
|
-
get ref() {
|
|
182
|
-
return tabRef
|
|
133
|
+
});
|
|
134
|
+
const ourProps = $derived(
|
|
135
|
+
mergeProps(
|
|
136
|
+
{
|
|
137
|
+
onkeydown: handleKeyDown,
|
|
138
|
+
onmousedown: handleMouseDown,
|
|
139
|
+
onclick: handleSelection,
|
|
140
|
+
id,
|
|
141
|
+
role: "tab",
|
|
142
|
+
type: resolvedType.type,
|
|
143
|
+
"aria-controls": panels[myIndex]?.current?.id,
|
|
144
|
+
"aria-selected": selected,
|
|
145
|
+
tabIndex: selected ? 0 : -1,
|
|
146
|
+
disabled: disabled || void 0,
|
|
147
|
+
autofocus
|
|
183
148
|
},
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
mergeProps(
|
|
188
|
-
{
|
|
189
|
-
onkeydown: handleKeyDown,
|
|
190
|
-
onmousedown: handleMouseDown,
|
|
191
|
-
onclick: handleSelection,
|
|
192
|
-
id,
|
|
193
|
-
role: "tab",
|
|
194
|
-
type: resolvedType.type,
|
|
195
|
-
"aria-controls": panels[myIndex]?.current?.id,
|
|
196
|
-
"aria-selected": selected,
|
|
197
|
-
tabIndex: selected ? 0 : -1,
|
|
198
|
-
disabled: disabled || undefined,
|
|
199
|
-
autofocus,
|
|
200
|
-
},
|
|
201
|
-
focusProps,
|
|
202
|
-
hoverProps,
|
|
203
|
-
pressProps
|
|
204
|
-
)
|
|
149
|
+
focusProps,
|
|
150
|
+
hoverProps,
|
|
151
|
+
pressProps
|
|
205
152
|
)
|
|
153
|
+
);
|
|
206
154
|
</script>
|
|
207
155
|
|
|
208
156
|
<ElementOrComponent {ourProps} {theirProps} {slot} defaultTag={DEFAULT_TAB_TAG} name="Tab" bind:ref />
|