Add .parent modifier for x-intersect#4839
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
left a comment
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!
Add a Cypress test that verifies x-intersect.parent observes the element relative to its parent (the IntersectionObserver root) rather than the browser viewport, and reword the docs for accuracy/grammar. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Pushed a follow-up commit (6704f82) to get this over the line on the review feedback: 1. Added a test ( Added a test('.parent observes the element relative to its parent, not the viewport', ...
get('span').should(haveText('0'))
get('#container').scrollTo(0, 250, {duration: 100}) // scroll within the parent, not the page
get('span').should(haveText('1'))I verified end-to-end in a real browser that the same markup gives 2. Fixed the docs (addressing both Copilot notes Josh flagged)
I left the (Pushed directly to the branch via maintainer edits — thanks @kevinruscoe!) |
|
thanks! |
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.