Skip to content

Commit 4a6a892

Browse files
authored
fix(FloatingContent): watch enabled dep (#1961)
1 parent 2514e78 commit 4a6a892

3 files changed

Lines changed: 18 additions & 3 deletions

File tree

‎.changeset/long-teeth-worry.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"bits-ui": patch
3+
---
4+
5+
fix(Floating): apply the content's z-index to the floating wrapper when force-mounted content opens

‎packages/bits-ui/src/lib/bits/utilities/floating-layer/use-floating-layer.svelte.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,9 @@ export class FloatingContentState {
269269
});
270270

271271
watch(
272-
() => this.contentRef.current,
273-
(contentNode) => {
274-
if (!contentNode || !this.opts.enabled.current) return;
272+
[() => this.contentRef.current, () => this.opts.enabled.current],
273+
([contentNode, enabled]) => {
274+
if (!contentNode || !enabled) return;
275275
const win = getWindow(contentNode);
276276
const rafId = win.requestAnimationFrame(() => {
277277
// avoid applying stale values when refs change quickly

‎tests/src/tests/popover/popover.browser.test.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,16 @@ it("should forceMount the content when `forceMount` is true and the `open` snipp
387387
await expectExists(t.getContent());
388388
});
389389

390+
it("should apply the content z-index to the wrapper when force-mounted content opens after mounting closed", async () => {
391+
render(PopoverForceMountTest, { contentProps: { style: "z-index: 50" } });
392+
const wrapper = () =>
393+
document.querySelector<HTMLElement>("[data-bits-floating-content-wrapper]");
394+
await expect.poll(() => wrapper()).not.toBeNull();
395+
await page.getByTestId("trigger").click();
396+
await expect.element(page.getByTestId("content")).toHaveAttribute("data-state", "open");
397+
await expect.poll(() => wrapper()?.style.zIndex).toBe("50");
398+
});
399+
390400
it("should correctly handle focus when closing one popover by clicking another popover's trigger", async () => {
391401
render(PopoverSiblingsTest);
392402
await page.getByTestId("open-1").click();

0 commit comments

Comments
 (0)