Skip to content
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

refactor(PageLayout): update sticky layout #2326

Merged
merged 14 commits into from
Oct 12, 2022
Merged

Conversation

joshblack
Copy link
Member

Closes https://github.com/github/primer/issues/1264

This PR presents an alternative to our PageLayout.Pane behavior in order to address some of these issues that have come up when using the existing implementation. Specifically, there are two challenges that have been identified:

  1. PageLayout.Pane will jump due to position: sticky
Screen.Recording.2022-09-09.at.4.03.11.PM.mov

This is due to the default implementation of position: sticky in the browser. At a certain point, the browser will scroll past the sticky parent and will scroll the overall viewport.

In the existing implementation, the height will re-calc and cause the sticky parent to come back into the viewport. This is what creates the jump as position: sticky comes back into play

  1. Elements within PageLayout.Pane will jump around when scrolling
Screen.Recording.2022-09-09.at.4.04.53.PM.mov

This is due to the height of PageLayout.Pane changing as a result of scrolling. In order to keep the elements in view within the scrolled container, it will attempt to restore the scroll position after the height changes. This leads to a jumpy effect

Proposal

This PR makes some trade-offs to allow for a sticky PageLayout.Pane without some of the challenges described above. Specifically, when encountering PageLayout.Footer (or another footer) the PageLayout.Pane component will follow position: sticky behavior and will not stick to the top.

Screen.Recording.2022-09-12.at.5.14.25.PM.mov

This approach keeps position: sticky in tack and avoids the jumpy-ness of previous attempts but unfortunately will not keep PageLayout.Pane stuck to the top when the footer comes into view as a result

@joshblack joshblack requested review from vdepizzol, colebemis and a team September 12, 2022 22:16
@changeset-bot
Copy link

changeset-bot bot commented Sep 12, 2022

🦋 Changeset detected

Latest commit: 96313cd

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

This PR includes changesets to release 1 package
Name Type
@primer/react 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

@joshblack
Copy link
Member Author

@colebemis one thing I noticed when testing is a z-index issue with the custom sticky header story. What would be the preferred way to address the z-index issue from your perspective? Wasn't sure if there was a system I should be using or if I should just bump the z-index on the custom sticky header and call it a day.

@github-actions
Copy link
Contributor

github-actions bot commented Sep 12, 2022

size-limit report 📦

Path Size
dist/browser.esm.js 77.66 KB (+0.02% 🔺)
dist/browser.umd.js 78.34 KB (+0.03% 🔺)

@joshblack joshblack temporarily deployed to github-pages September 12, 2022 22:25 Inactive
@colebemis
Copy link
Contributor

@colebemis one thing I noticed when testing is a z-index issue with the custom sticky header story. What would be the preferred way to address the z-index issue from your perspective? Wasn't sure if there was a system I should be using or if I should just bump the z-index on the custom sticky header and call it a day.

We don't have any kind of z-index system. Let's bump the z-index and call it a day 😉

@joshblack
Copy link
Member Author

Perfect, thanks @colebemis!

@joshblack joshblack temporarily deployed to github-pages September 14, 2022 17:07 Inactive
@joshblack joshblack temporarily deployed to github-pages September 26, 2022 17:56 Inactive
@joshblack joshblack temporarily deployed to github-pages October 12, 2022 19:10 Inactive
@joshblack
Copy link
Member Author

Just wanted to follow up here, reached out over in web systems and paired up with @jonrohan to see what we could do with this pattern to avoid the "jumpiness".

When researching more, it seems like this behavior occurs in the original codepen and other implementations across Primer. Below are two examples from different areas:

I tried to take existing videos and slow them down to show where the jump was coming from, hope it makes it clearer!

It seems like the root cause is the time it takes to update the height of the pane in order for position: sticky to get back in. As the amount of content grows in the Pane, the longer it takes for this update to occur.

As an interim trade-off, this PR uses native position: sticky behavior. This leads to the top of the pane not remaining sticky as the footer comes into view. If we can find a way to do this efficiently as content grows then this should be a quick fix to add back in!

Hope that makes sense, let me know if there are any questions!

Copy link
Contributor

@colebemis colebemis left a comment

Choose a reason for hiding this comment

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

Thanks for doing a thorough evaluation of our options here, @joshblack! This PR feels like our best option at this point. Let's go ahead and merge it. As you said, we can revisit this later if we find a better solution.

src/PageLayout/PageLayout.tsx Outdated Show resolved Hide resolved
@joshblack joshblack temporarily deployed to github-pages October 12, 2022 19:33 Inactive
joshblack and others added 2 commits October 12, 2022 14:37
Co-authored-by: Cole Bemis <colebemis@github.com>
@joshblack joshblack temporarily deployed to github-pages October 12, 2022 19:46 Inactive
@joshblack joshblack temporarily deployed to github-pages October 12, 2022 20:20 Inactive
@joshblack joshblack temporarily deployed to github-pages October 12, 2022 20:33 Inactive
@joshblack joshblack merged commit 31bbec8 into main Oct 12, 2022
@joshblack joshblack deleted the update-sticky-page-layout branch October 12, 2022 20:46
@primer-css primer-css mentioned this pull request Oct 12, 2022
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