Skip to content

Commit

Permalink
fix(popper): hideWhenDetached
Browse files Browse the repository at this point in the history
  • Loading branch information
segunadebayo committed Dec 30, 2024
1 parent d29c8a5 commit 5fa08c5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .changeset/shy-days-kick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@zag-js/popper": patch
---

Fix issue where `positioning.hideWhenDetached` doesn't remove the `visibility:hidden` attached to the positioner when
reference comes back into view
17 changes: 12 additions & 5 deletions packages/utilities/popper/src/get-placement.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { AutoUpdateOptions, Middleware, Placement } from "@floating-ui/dom"
import { arrow, autoUpdate, computePosition, flip, hide, limitShift, offset, shift, size } from "@floating-ui/dom"
import { getWindow, raf } from "@zag-js/dom-query"
import { getComputedStyle, getWindow, raf } from "@zag-js/dom-query"
import { compact, isNull, noop, runIfFn } from "@zag-js/utils"
import { getAnchorElement } from "./get-anchor"
import { rectMiddleware, shiftArrowMiddleware, transformOriginMiddleware } from "./middleware"
Expand Down Expand Up @@ -175,15 +175,22 @@ function getPlacementImpl(referenceOrVirtual: MaybeRectElement, floating: MaybeE
floating.style.setProperty("--x", `${x}px`)
floating.style.setProperty("--y", `${y}px`)

if (options.hideWhenDetached && pos.middlewareData.hide?.referenceHidden) {
floating.style.setProperty("visibility", "hidden")
if (options.hideWhenDetached) {
const isHidden = pos.middlewareData.hide?.referenceHidden
if (isHidden) {
floating.style.setProperty("visibility", "hidden")
floating.style.setProperty("pointer-events", "none")
} else {
floating.style.removeProperty("visibility")
floating.style.removeProperty("pointer-events")
}
}

const contentEl = floating.firstElementChild

if (contentEl) {
const zIndex = win.getComputedStyle(contentEl).zIndex
floating.style.setProperty("--z-index", zIndex)
const styles = getComputedStyle(contentEl)
floating.style.setProperty("--z-index", styles.zIndex)
}
}

Expand Down

0 comments on commit 5fa08c5

Please sign in to comment.