-
Notifications
You must be signed in to change notification settings - Fork 536
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
PageLayout.Pane: Add sticky
prop
#2212
Conversation
🦋 Changeset detectedLatest commit: 295a1ae The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
size-limit report 📦
|
|
||
// Safari's elastic scroll feature allows you to scroll beyond the scroll height of the page. | ||
// We need to account for this when calculating the offset. | ||
const overflowScroll = Math.max(window.scrollY + window.innerHeight - document.body.scrollHeight, 0) |
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.
Do you think this should be calculated on the scrollcontainer? Or is the PageLayout
always meant to be used as a top level component?
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.
PageLayout should always be the top-level component. But this is a good consideration. I'll keep it as window
for now and adjust it if needed.
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.
Actually, it looks like memex uses PageLayout inside a scroll container. I'll fix this in this PR
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.
PageLayout should always be the top-level component.
Can you say more about this, would the top level navigation be inside PageLayout.Header?
Right now, I think issues has top level navigation and page layout as siblings, so there's some margin on top
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.
Yeah, I was wrong about PageLayout always being top-level. @joshblack and I just updated the implementation to work if PageLayout is nested in a scroll container: 52e174f
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.
I don't have a lot of comments regarding implementation. react-interaction-observer
seems like a nifty little library. I wonder why the size-limit did not alert us of the additional 4kb 🤔
Anyways, noticed that this seemed like a great opportunity for some interactive tests!
Here's a PR to this branch with a couple of tests on the storybooks
#2224
For further info check my ADR https://github.com/primer/react/pull/2223/files
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.
Suggested some improvements for the docs, approving in advance 👍
@@ -1,6 +1,7 @@ | |||
import React from 'react' | |||
import {act, render} from '@testing-library/react' | |||
import MatchMediaMock from 'jest-matchmedia-mock' | |||
import 'react-intersection-observer/test-utils' |
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.
oooh how do we use these?
{children} | ||
</Box> | ||
|
||
{/* Track the bottom of the content region so we can calculate the height of the pane region */} | ||
<Box ref={contentBottomRef} /> |
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.
thanks for the helpful comment!
|
||
// Safari's elastic scroll feature allows you to scroll beyond the scroll height of the page. | ||
// We need to account for this when calculating the offset. | ||
const overflowScroll = Math.max(window.scrollY + window.innerHeight - document.body.scrollHeight, 0) |
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.
PageLayout should always be the top-level component.
Can you say more about this, would the top level navigation be inside PageLayout.Header?
Right now, I think issues has top level navigation and page layout as siblings, so there's some margin on top
const overflowScroll = Math.max(window.scrollY + window.innerHeight - document.body.scrollHeight, 0) | ||
|
||
setHeight(`calc(100vh - ${topOffset + bottomOffset - overflowScroll}px)`) | ||
}, [contentTopEntry, contentBottomEntry]) |
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.
I like this optimisation is a lot!
Co-authored-by: Josh Black <joshblack@users.noreply.github.com>
Motivation
Pages with a lot of content (examples: files changed tab, settings page, etc.) might want to display a sticky side pane that stays in view as you scroll through the content. This is not currently supported by the
PageLayout
componentSummary
This PR adds a
sticky
prop to thePageLayout.Pane
component that provides a convenient way for consumers to make side panes sticky:Here's a quick demo of the sticky behavior:
CleanShot.2022-08-02.at.13.40.33.mp4
Implementation
The sticky is more complex than you might expect so I recorded a quick demo to explain why the complexity exists and how it works:
🎥 🍿 https://share.cleanshot.com/O9uSpc
Merge checklist
Added/updated testsTake a look at the What we look for in reviews section of the contributing guidelines for more information on how we review PRs.