@pzerelles/headlessui-svelte 2.1.2-next.48 → 2.1.2-next.49

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.
@@ -27,8 +27,8 @@
27
27
  *
28
28
  * ```tsx
29
29
  * <Transition show={true}>
30
- * <Transition.Child enter="duration-100"><div>Child 1</div></Transition.Child>
31
- * <Transition.Child enter="duration-200"><div>Child 2</div></Transition.Child>
30
+ * <TransitionChild enter="duration-100"><div>Child 1</div></TransitionChild>
31
+ * <TransitionChild enter="duration-200"><div>Child 2</div></TransitionChild>
32
32
  * </Transition>
33
33
  * ```
34
34
  *
@@ -39,9 +39,17 @@
39
39
  export function shouldForwardRef(props: TransitionRootProps) {
40
40
  return (
41
41
  // If we have any of the enter/leave classes
42
- Boolean(props.enter || props.enterFrom || props.enterTo || props.leave || props.leaveFrom || props.leaveTo) ||
42
+ Boolean(
43
+ props.enter ||
44
+ props.enterFrom ||
45
+ props.enterTo ||
46
+ props.leave ||
47
+ props.leaveFrom ||
48
+ props.leaveTo ||
49
+ props.class
50
+ ) ||
43
51
  // If the `as` prop is not a Fragment
44
- !props.asChild
52
+ props.asChild
45
53
  )
46
54
  }
47
55
  </script>
@@ -86,7 +94,7 @@
86
94
  const { register, unregister } = $derived(parentNesting)
87
95
 
88
96
  onMount(() => {
89
- if (requiresRef) {
97
+ if (requiresRef || element) {
90
98
  container.current = element ?? null
91
99
  containerElement = element
92
100
  }
@@ -113,7 +121,7 @@
113
121
  //[state, container, register, unregister, show, strategy]
114
122
 
115
123
  $effect(() => {
116
- if (!requiresRef) return
124
+ if (!requiresRef && !element) return
117
125
 
118
126
  if (_state === TreeStates.Visible && container.current === null) {
119
127
  throw new Error("Did you forget to passthrough the actual DOM node as `element`?")
@@ -169,7 +177,7 @@
169
177
  }
170
178
 
171
179
  $effect(() => {
172
- if (requiresRef && transition) return
180
+ if ((requiresRef || element) && transition) return
173
181
 
174
182
  // When we don't transition, then we can complete the transition
175
183
  // immediately.
@@ -183,7 +191,7 @@
183
191
  if (!transition) return false
184
192
 
185
193
  // If we don't require a ref, then we can't transition.
186
- if (!requiresRef) return false
194
+ if (!requiresRef && !element) return false
187
195
 
188
196
  // If the server handoff isn't completed yet, we can't transition.
189
197
  //if (!ready) return false
@@ -219,7 +227,7 @@
219
227
  classNames(
220
228
  // Incoming classes if any
221
229
  // all components accept className (but all HTML elements do)
222
- theirProps.asChild
230
+ theirProps.asChild || !requiresRef
223
231
  ? undefined
224
232
  : typeof theirProps.class === "function"
225
233
  ? theirProps.class({ element })
@@ -243,6 +251,7 @@
243
251
  !transitionData.transition && show && entered
244
252
  )?.trim() || undefined, // If `class` is an empty string, we can omit it
245
253
  ...transitionDataAttributes(transitionData),
254
+ ...(!theirProps.asChild && !requiresRef ? { asChild: true } : {}),
246
255
  })
247
256
  )
248
257
 
@@ -9,8 +9,8 @@ import { type TransitionChildProps } from "./TransitionChild.svelte";
9
9
  *
10
10
  * ```tsx
11
11
  * <Transition show={true}>
12
- * <Transition.Child enter="duration-100"><div>Child 1</div></Transition.Child>
13
- * <Transition.Child enter="duration-200"><div>Child 2</div></Transition.Child>
12
+ * <TransitionChild enter="duration-100"><div>Child 1</div></TransitionChild>
13
+ * <TransitionChild enter="duration-200"><div>Child 2</div></TransitionChild>
14
14
  * </Transition>
15
15
  * ```
16
16
  *
@@ -18,7 +18,7 @@ import { type TransitionChildProps } from "./TransitionChild.svelte";
18
18
  * `Transition` parent, which is a `Fragment`, is not. So we should not forward
19
19
  * the ref to the `Fragment`.
20
20
  */
21
- export declare function shouldForwardRef(props: TransitionRootProps): boolean;
21
+ export declare function shouldForwardRef(props: TransitionRootProps): boolean | undefined;
22
22
  declare const InternalTransitionChild: import("svelte").Component<TransitionChildProps, {}, "element">;
23
23
  type InternalTransitionChild = ReturnType<typeof InternalTransitionChild>;
24
24
  export default InternalTransitionChild;
@@ -11,14 +11,14 @@ export var TreeStates;
11
11
  export function useTransitionContext() {
12
12
  const context = getContext("TransitionContext");
13
13
  if (!context) {
14
- throw new Error("A <Transition.Child /> is used but it is missing a parent <Transition /> or <Transition.Root />.");
14
+ throw new Error("A <TransitionChild /> is used but it is missing a parent <Transition /> or <Transition.Root />.");
15
15
  }
16
16
  return context;
17
17
  }
18
18
  export function useParentNesting() {
19
19
  const context = getContext("NestingContext");
20
20
  if (!context) {
21
- throw new Error("A <Transition.Child /> is used but it is missing a parent <Transition /> or <Transition.Root />.");
21
+ throw new Error("A <TransitionChild /> is used but it is missing a parent <Transition /> or <Transition.Root />.");
22
22
  }
23
23
  return context;
24
24
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pzerelles/headlessui-svelte",
3
- "version": "2.1.2-next.48",
3
+ "version": "2.1.2-next.49",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build && npm run package",