-
Notifications
You must be signed in to change notification settings - Fork 54
Fix AnchorNav layout shift when sticky #1124
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
Conversation
🦋 Changeset detectedLatest commit: 4efb5a1 The changes in this PR will be included in the next version bump. This PR includes changesets to release 8 packages
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 |
🟢 No design token changes found |
🟢 No visual differences foundOur visual comparison tests did not find any differences in the UI. |
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 a layout shift issue in the AnchorNav component when it becomes sticky by adding a spacer element to compensate for the lost height.
- Adds a height-compensating spacer element that appears only when the nav is sticky
- Updates tests to cover the new spacer behavior with proper mocking of IntersectionObserver and scroll events
- Fixes two broken stories by adding top offset to prevent the AnchorNav from being too close to the page top
Reviewed Changes
Copilot reviewed 4 out of 16 changed files in this pull request and generated 3 comments.
File | Description |
---|---|
AnchorNav.tsx | Adds navHeight state tracking and conditional spacer element to prevent layout shift |
AnchorNav.test.tsx | Comprehensive test setup for intersection observer and scroll behavior, plus test for spacer functionality |
AnchorNav.features.stories.tsx | Adds top padding to stories to fix positioning issues |
tame-boxes-shout.md | Changeset documenting the layout shift fix |
Summary
Resolves https://github.com/github/primer/issues/5353
Fixes a bug where AnchorNav didn't compensate for lost height when it becomes sticky. This caused noticeably jumpy layout shift underneath the sticky element.
List of notable changes:
What should reviewers focus on?
Steps to test:
Supporting resources (related issues, external links, etc):
Contributor checklist:
update snapshots
label to the PR)Reviewer checklist:
Screenshots:
Fixed in Storybook:
Screen.Recording.2025-07-30.at.13.43.13.mov
Screen.Recording.2025-07-30.at.13.42.46.mov
Fixed in Dotcom:
Screen.Recording.2025-07-31.at.16.09.04.mov
Screen.Recording.2025-07-31.at.16.08.33.mov
Note
In dotcom there is an additional x-axis shift when anchor nav becomes sticky. This is because the AnchorNav is wrapped in a Section component, which includes a max-width that is no longer applied when the nav becomes stuck. AnchorNav isn't intended to be used inside a grid or width-constrained container. Once that's removed, it will behave as-seen in the video above. This PR won't address this. It instead fixes the bug causing vertical layout shift. cc/ @seangolob