-
Notifications
You must be signed in to change notification settings - Fork 56
Fix popover scroll parent detection in nested shadow DOM containers #1178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: iOvergaard <[email protected]>
- Clear scroll parents array before repopulating to prevent duplicates - Add shadow DOM traversal support to old popover element - Enhanced both uui-popover and uui-popover-container components Co-authored-by: iOvergaard <[email protected]>
- Created test cases to verify scroll parent detection - Added visual demo to showcase the fix - Verified build and lint pass successfully Co-authored-by: iOvergaard <[email protected]>
Remove demo and extra test files, keeping only the essential fix and enhanced tests Co-authored-by: iOvergaard <[email protected]>
…c (recalculate every time)
Azure Static Web Apps: Your stage site is ready! Visit it here: https://delightful-beach-055ecb503-1178.westeurope.azurestaticapps.net |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes scroll parent detection issues in popovers within nested shadow DOM containers. The main problem was that popovers couldn't properly identify their correct scroll parents across shadow DOM boundaries, causing incorrect positioning when intermediate scroll containers were scrolled.
- Prevents duplicate scroll parent accumulation when popovers are opened multiple times
- Adds proper shadow DOM boundary traversal for scroll parent detection
- Implements conditional logic for excluding static parents based on position state
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
File | Description |
---|---|
packages/uui-popover/lib/uui-popover.element.ts | Adds scroll parent reset logic and shadow DOM traversal helper method |
packages/uui-popover-container/lib/uui-popover-container.element.ts | Fixes duplicate scroll parents and improves static parent exclusion logic |
packages/uui-popover-container/lib/uui-popover-container.test.ts | Adds comprehensive tests for nested shadow DOM scroll parent detection |
packages/uui-popover-container/lib/uui-popover-container.story.ts | Refactors story configuration and minor styling improvements |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Azure Static Web Apps: Your stage site is ready! Visit it here: https://delightful-beach-055ecb503-1178.westeurope.azurestaticapps.net |
|
Azure Static Web Apps: Your stage site is ready! Visit it here: https://delightful-beach-055ecb503-1178.westeurope.azurestaticapps.net |
Fixes the issue where popovers inside nested shadow DOM scroll containers could not properly detect their scroll parents, causing them to scroll incorrectly with grandparent frames instead of staying positioned relative to their triggers.
How to test
Check Storybook out on: https://delightful-beach-055ecb503-1178.westeurope.azurestaticapps.net/?path=/story/uui-popover-container--inside-shadow-dom-scroll-container
Problem
When a popover was placed inside another scrolling target within shadow DOM boundaries, it would fail to bind to the correct scroll parents. This resulted in popovers that would move incorrectly when intermediate scroll containers were scrolled, as reported in #1161.
The issue manifested in scenarios like:
When scrolling the inner container, the popover would not follow the button correctly.
Root Causes
Duplicate scroll parents: The
#getScrollParents()
method inuui-popover-container
didn't reset the scroll parents array before repopulating it, causing duplicate event listeners and incorrect behavior when the popover was opened multiple times.Shadow DOM boundary traversal: The older
uui-popover
component only usedparentElement
for DOM traversal, which doesn't cross shadow DOM boundaries, missing scroll containers in parent shadow roots.Solution
For
uui-popover-container
:this.#scrollParents = [];
at the beginning of#getScrollParents()
to prevent accumulation of duplicate scroll parentsFor
uui-popover
:_getAncestorElement()
helper method that properly traverses shadow DOM boundaries by checking for shadow root hosts whenparentElement
is null_getScrollParents()
to use the new traversal methodCloses #1161