Skip to content

Commit ddb75cf

Browse files
committed
tests passing
1 parent 1553c67 commit ddb75cf

File tree

6 files changed

+116
-132
lines changed

6 files changed

+116
-132
lines changed

packages/floating-ui-svelte/src/hooks/use-floating.svelte.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,12 @@ class FloatingOptions<RT extends ReferenceType = ReferenceType> {
122122
reason?: OpenChangeReason,
123123
) => void;
124124
nodeId: ReadableBox<string | undefined>;
125-
#stableReference = $state<Element | null>(null);
126-
#stableFloating = $state<HTMLElement | null>(null);
127-
reference: WritableBox<Element | null> = box(null);
128-
floating: WritableBox<HTMLElement | null> = box(null);
129125
floatingProp = $derived.by(() => extract(this.options.floating, null));
130126
referenceProp = $derived.by(() => extract(this.options.reference, null));
127+
#stableReference = $state<Element | null>(null);
128+
#stableFloating = $state<HTMLElement | null>(null);
129+
reference: WritableBox<Element | null>;
130+
floating: WritableBox<HTMLElement | null>;
131131
constructor(private readonly options: UseFloatingOptions<RT>) {
132132
this.open = box.with(() => extract(options.open, true));
133133
this.placement = box.with(() => extract(options.placement, "bottom"));
@@ -156,8 +156,8 @@ class FloatingOptions<RT extends ReferenceType = ReferenceType> {
156156
this.onFloatingChange(node);
157157
},
158158
);
159-
this.reference.current = this.referenceProp;
160-
this.floating.current = this.floatingProp;
159+
this.reference.current = extract(this.options.reference, null);
160+
this.floating.current = extract(this.options.floating, null);
161161

162162
$effect.pre(() => {
163163
if (this.floatingProp) {
@@ -296,6 +296,8 @@ class FloatingState<RT extends ReferenceType = ReferenceType> {
296296
context: FloatingContext<RT>;
297297

298298
constructor(private readonly options: FloatingOptions<RT>) {
299+
console.log(options.reference.current);
300+
299301
const internalRootContext = useFloatingRootContext({
300302
open: () => options.open.current ?? true,
301303
reference: () => options.reference.current,
@@ -337,7 +339,7 @@ class FloatingState<RT extends ReferenceType = ReferenceType> {
337339
}
338340

339341
get reference() {
340-
return this.#positionReference as RT | null;
342+
return this.options.reference.current as RT | null;
341343
}
342344

343345
set reference(node: RT | null) {

packages/floating-ui-svelte/src/hooks/use-position.svelte.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ class PositionState<RT extends ReferenceType = ReferenceType> {
160160
) {
161161
this.data.strategy = this.options.strategy.current;
162162
this.data.placement = this.options.placement.current;
163+
this.update = this.update.bind(this);
163164

164165
$effect.pre(() => {
165166
if (this.rootContext.open || !this.data.isPositioned) return;
@@ -172,7 +173,7 @@ class PositionState<RT extends ReferenceType = ReferenceType> {
172173
return this.options.whileElementsMounted(
173174
this.referenceEl,
174175
this.options.floating.current,
175-
() => this.update(),
176+
this.update,
176177
);
177178
}
178179

0 commit comments

Comments
 (0)