Skip to content

Add fixed positioning option to x-anchor directive#4773

Open
nicolagianelli wants to merge 1 commit intoalpinejs:mainfrom
nicolagianelli:fixed-anchor
Open

Add fixed positioning option to x-anchor directive#4773
nicolagianelli wants to merge 1 commit intoalpinejs:mainfrom
nicolagianelli:fixed-anchor

Conversation

@nicolagianelli
Copy link
Contributor

What does this PR do?
This PR adds a new .fixed modifier to the x-anchor plugin to support fixed positioning.

Why is this needed?
Currently, x-anchor hardcodes position: absolute when applying styles. This works for most cases, but breaks down in scenarios where the reference element is inside a container with overflow: hidden, or when the developer wants a popover/tooltip to stay pinned to the viewport during scrolling. Floating UI natively supports a fixed positioning strategy to solve this exact problem, but Alpine didn't have a way to pass that configuration through.

How does it work?
Checks for the .fixed modifier in getOptions(). If present, the strategy is set to 'fixed' (otherwise it defaults to 'absolute').
Passes the strategy configuration into Floating UI's computePosition method.
Plumbs the strategy argument through to the setStyles() helper function so it applies position: fixed instead of hardcoding absolute.

Backward Compatibility / Breaking Changes:
This is a fully additive feature. Existing x-anchor implementations will continue to default to position: absolute and behave exactly as they did before. No breaking changes are introduced.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant