Skip to content

Commit

Permalink
Added sync external test aswell as ensure only defined dom nodes are …
Browse files Browse the repository at this point in the history
…synced with effects (#145)
  • Loading branch information
Hugos68 authored Jan 1, 2025
1 parent 4244127 commit 56a804b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/twelve-tables-press.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@skeletonlabs/floating-ui-svelte": patch
---

Ensures referenced dom elements are synced externally.
10 changes: 8 additions & 2 deletions packages/floating-ui-svelte/src/hooks/use-floating.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,11 +332,17 @@ function useFloating(options: UseFloatingOptions = {}): UseFloatingReturn {
};

$effect.pre(() => {
elements.reference = options.elements?.reference;
if (!options.elements || !options.elements.reference) {
return;
}
elements.reference = options.elements.reference;
});

$effect.pre(() => {
elements.floating = options.elements?.floating;
if (!options.elements || !options.elements.floating) {
return;
}
elements.floating = options.elements.floating;
});

$effect.pre(() => {
Expand Down
19 changes: 19 additions & 0 deletions packages/floating-ui-svelte/test/hooks/use-floating.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,25 @@ describe("useFloating", () => {
});
}),
);
it(
"is synced externally",
withRunes(() => {
const elements = $state(createElements());

const floating = useFloating({
get elements() {
return elements;
},
});

const newElements = createElements();

floating.elements.reference = newElements.reference;
floating.elements.floating = newElements.floating;

expect(elements).toEqual(newElements);
}),
);
});

describe("transform", () => {
Expand Down

0 comments on commit 56a804b

Please sign in to comment.