Skip to content

Conversation

pksjce
Copy link
Contributor

@pksjce pksjce commented Jul 10, 2025

@pksjce pksjce requested a review from francinelucca July 10, 2025 06:10
Copy link

changeset-bot bot commented Jul 10, 2025

🦋 Changeset detected

Latest commit: 9e0416b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/behaviors Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pksjce pksjce changed the title Failing test for anchoredPosition showing stuff below scrollview Fix anchoredPosition to position overlay in visible viewport even if out of screen scrollspace is available below the anchor element Jul 11, 2025
@pksjce pksjce marked this pull request as ready for review July 11, 2025 04:20
@Copilot Copilot AI review requested due to automatic review settings July 11, 2025 04:20
@pksjce pksjce requested a review from a team as a code owner July 11, 2025 04:20
Copy link

@Copilot Copilot AI left a 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 an issue where overlays were not properly positioned within the visible viewport when scrollable content existed below the anchor element. The fix ensures that when the clipping node is the document body, the viewport height is used instead of the body's potentially larger scrollable height for positioning calculations.

  • Updated clipping rect calculation to use viewport height for document.body
  • Added comprehensive test case for the bottom viewport positioning scenario
  • Added changeset documentation for the patch release

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/anchored-position.ts Modified getClippingRect to use window.innerHeight directly when clipping node is document.body
src/tests/anchored-position.test.ts Added test case verifying overlay flips to top when positioned at bottom of viewport with scrollable content
.changeset/clean-coins-lie.md Added changeset entry documenting the fix

height:
clippingNode === document.body
? window.innerHeight
: Math.max(elemRect.height - borderTop - borderBottom, -Infinity),
Copy link
Preview

Copilot AI Jul 11, 2025

Choose a reason for hiding this comment

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

The use of -Infinity as a fallback value in Math.max is unclear and could be confusing. Consider using 0 or a more descriptive constant, or add a comment explaining why -Infinity is the appropriate fallback.

Suggested change
: Math.max(elemRect.height - borderTop - borderBottom, -Infinity),
: Math.max(elemRect.height - borderTop - borderBottom, 0), // Fallback to 0 to ensure non-negative height

Copilot uses AI. Check for mistakes.

@pksjce pksjce force-pushed the pk/anchoredposition branch from 9e0416b to 839e365 Compare July 11, 2025 04:21
@@ -0,0 +1,5 @@
---
"@primer/behaviors": patch
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think its a patch because it fixes issue without breaking any other test cases

Comment on lines +236 to +240
// If the clipping node is document.body, use the viewport height instead of body height
height:
clippingNode === document.body
? window.innerHeight
: Math.max(elemRect.height - borderTop - borderBottom, -Infinity),
Copy link
Member

Choose a reason for hiding this comment

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

Let's add this fix in a way that we can revert back to the previous implementation quickly if we find any issues 🙏
See https://github.com/github/primer/issues/5358#issuecomment-3059248179

@pksjce pksjce closed this Jul 14, 2025
@pksjce
Copy link
Contributor Author

pksjce commented Jul 14, 2025

This PR needs

  • A more robust fix required. Current fix passes test cases but appears wonky in the ActionMenu storybook.
  • More testing to see if any existing use cases breaks
  • Pass FF from @primer/react for smoother rollout since this is a risky fix that has a lot of points of usage

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.

2 participants