Skip to content

Add .parent modifier for x-intersect#4839

Open
kevinruscoe wants to merge 2 commits into
alpinejs:mainfrom
kevinruscoe:main
Open

Add .parent modifier for x-intersect#4839
kevinruscoe wants to merge 2 commits into
alpinejs:mainfrom
kevinruscoe:main

Conversation

@kevinruscoe

Copy link
Copy Markdown

This pull request adds support for using a parent element as the viewport for x-intersect in 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 .parent modifier.

Feature: Support for parent viewport in IntersectionObserver

  • packages/intersect/src/index.js: Added logic to set the root option to the parent element when the parent modifier is present, enabling intersection observation relative to the parent container.

Documentation update

Copilot AI review requested due to automatic review settings May 29, 2026 16:38

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 root configuration to IntersectionObserver options when .parent is used.
  • Document the new .parent modifier 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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update this.

Comment thread packages/docs/src/en/plugins/intersect.md
@joshhanley joshhanley changed the title Add parent modifier for x-intersect and update documentation Add .parent modifier for x-intersect Jun 1, 2026

@joshhanley joshhanley left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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!

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.

3 participants