Add .parent modifier for x-intersect#4839
Open
kevinruscoe wants to merge 2 commits into
Open
Conversation
… rather than the default of window.
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds a .parent modifier to the x-intersect plugin so the underlying IntersectionObserver can use the element’s parent as the observation root, and documents the new modifier.
Changes:
- Add
rootconfiguration toIntersectionObserveroptions when.parentis used. - Document the new
.parentmodifier in the intersect plugin docs.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/intersect/src/index.js | Adds support for .parent by setting IntersectionObserver’s root to the element’s parent. |
| packages/docs/src/en/plugins/intersect.md | Documents the new .parent modifier and provides an example. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| Allows for the underlying `IntersectionObserver` to use the viewport of the parent element, rather than the default, which is the browser. | ||
|
|
||
| ```alpine | ||
| <div x-intersect.parent="shown = true">...</div> // Mark as shown when element is moves inside it's parents viewport. |
.parent modifier for x-intersect
joshhanley
requested changes
Jun 1, 2026
joshhanley
left a comment
Collaborator
There was a problem hiding this comment.
@kevinruscoe thanks for the PR! Can you please add some tests? Can you also address Copilot's second concern regarding the grammar in the comment. Thanks!
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.
This pull request adds support for using a parent element as the viewport for
x-intersectin Alpine.js, instead of the default browser viewport. This allows elements to be observed relative to their parent container, which is useful for more complex layouts. Documentation has also been updated to explain the new.parentmodifier.Feature: Support for parent viewport in IntersectionObserver
packages/intersect/src/index.js: Added logic to set therootoption to the parent element when theparentmodifier is present, enabling intersection observation relative to the parent container.Documentation update
packages/docs/src/en/plugins/intersect.md: Added documentation for the new.parentmodifier, explaining its usage and providing an example.