Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: positioning auto update #1213

Merged
merged 1 commit into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/little-pillows-grab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@zag-js/popper": patch
---

Fix issue where positioned components don't respond to window resizing.
1 change: 0 additions & 1 deletion packages/utilities/popper/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
},
"dependencies": {
"@zag-js/dom-query": "workspace:*",
"@zag-js/element-rect": "workspace:*",
"@zag-js/utils": "workspace:*",
"@floating-ui/dom": "1.6.1"
},
Expand Down
58 changes: 0 additions & 58 deletions packages/utilities/popper/src/auto-update.ts

This file was deleted.

18 changes: 13 additions & 5 deletions packages/utilities/popper/src/get-placement.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import type { Middleware } from "@floating-ui/dom"
import { arrow, computePosition, flip, offset, shift, size } from "@floating-ui/dom"
import type { AutoUpdateOptions, Middleware } from "@floating-ui/dom"
import { arrow, autoUpdate, computePosition, flip, offset, shift, size } from "@floating-ui/dom"
import { getWindow, raf } from "@zag-js/dom-query"
import { compact, isNull, runIfFn } from "@zag-js/utils"
import { autoUpdate } from "./auto-update"
import { compact, isNull, noop, runIfFn } from "@zag-js/utils"
import { getAnchorElement } from "./get-anchor"
import { __shiftArrow, __transformOrigin } from "./middleware"
import { getPlacementDetails } from "./placement"
Expand Down Expand Up @@ -93,6 +92,14 @@ function __size(opts: PositioningOptions) {
})
}

function getAutoUpdateOptions(opts?: boolean | AutoUpdateOptions): AutoUpdateOptions {
if (!opts) return {}
if (opts === true) {
return { ancestorResize: true, ancestorScroll: true, elementResize: true, layoutShift: true }
}
return opts
}

function getPlacementImpl(referenceOrVirtual: MaybeRectElement, floating: MaybeElement, opts: PositioningOptions = {}) {
const reference = getAnchorElement(referenceOrVirtual, opts.getAnchorRect)

Expand Down Expand Up @@ -158,7 +165,8 @@ function getPlacementImpl(referenceOrVirtual: MaybeRectElement, floating: MaybeE
}
}

const cancelAutoUpdate = options.listeners ? autoUpdate(reference, floating, update, options.listeners) : undefined
const autoUpdateOptions = getAutoUpdateOptions(options.listeners)
const cancelAutoUpdate = options.listeners ? autoUpdate(reference, floating, update, autoUpdateOptions) : noop

update()

Expand Down
3 changes: 1 addition & 2 deletions packages/utilities/popper/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { Boundary, ComputePositionReturn, Placement, VirtualElement } from "@floating-ui/dom"
import type { AutoUpdateOptions } from "./auto-update"
import type { AutoUpdateOptions, Boundary, ComputePositionReturn, Placement, VirtualElement } from "@floating-ui/dom"

export type MaybeRectElement = HTMLElement | VirtualElement | null

Expand Down
3 changes: 0 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading