Add fixed positioning option to x-anchor directive#4773
Open
nicolagianelli wants to merge 1 commit intoalpinejs:mainfrom
Open
Add fixed positioning option to x-anchor directive#4773nicolagianelli wants to merge 1 commit intoalpinejs:mainfrom
nicolagianelli wants to merge 1 commit intoalpinejs:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.