-
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
Scroll AnchoredOverlay when it's inside a scrolling child of the body #4195
Conversation
🦋 Changeset detectedLatest commit: f1837c4 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 📦
|
The build error here might be due to the same issue as described on this StackOverflow post. |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
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 think observing changes is the right way to handle this. It causes some quite poor performance issues by causing layout thrashing and bridging JS binding - hence you adding a debounce, which then causes jankyness. I'm fairly sure it can be fixed in CSS.
@keithamus That would be really cool! That would be the preference, we can treat this PR as the backup plan My initial exploration was a quite a while ago, so I don't remember if I explored css solution or not (maybe I was only trying to extend getAnchoredPosition without changing it 🤔) |
Closing, we can always reopen if the CSS investigation doesn't bear fruit. |
Hi again! Does anyone have this on their list? Don't want to completely drop this either. |
Not on my list @siddharthkp |
Closes https://github.com/github/primer/issues/1421
Adds the code @siddharthkp created for his PR to solve this problem. When you scroll within a parent element that isn't the main body element, the Anchor now updates.
Original functionality
A video showing a panel of buttons, the user opens an overlay showing a cat by pressing one of the buttons. When the user scrolls the panel, the overlay cat remains fixed in place.
Original.functionality.mov
New functionality
A video showing a panel of buttons, the user opens an overlay showing a cat by pressing one of the buttons. When the user scrolls the panel, the overlay follows the button that was pressed. There's an issue shows where the overlay moves position based on the clipping of the parent rect.
New.functionality.mov
Changelog
New
This adds a new
useElementObserver
to observe when the rect for an element changes.Changed
Changes
useAnchoredPosition
andAnchoredOverlay
to use the new hook.Removed
Rollout strategy
Testing & Reviewing
I'm not totally happy with this but couldn't see a better way to do it. I removed the
instanceof Element
because if broke the gatsby SSR build (Element isn't available server side). I've tried to use the solutions suggested by StackOverflow however excluding the library from the build isn't possible (we have to exclude the whole component, but then the Javascript still gets build for every other component so it still fails - I think some work on src/hooks/index.ts might resolve this but that was a rabbit hole I didn't have time to explore) and trying to only load the code client-side was proving to be fiddly and hacky given the structure of the code. In the end, I opted for the simplest solution 🤷Do we need to worry about the increase to the size of
browser.*.js
?I had a look at the weird issue whereby the overlay jumps position when the scroll takes the anchor button into a position where
updatePosition
returns a different orientation. We can fix this, but it's a much larger lift (and I believe this issue also exists for other overlays which don't suffer from this problem). To fix it, we'll probably need to reworkuseAnchoredPosition
so thatupdatePosition
is only called when the overlay is first opened, subsequent changes should move the overlay based on the original orientation of the overlay (resetting when closed).Finally: do we want to add this functionality to
AutocompleteOverlay
and/orSelectPanel
?Merge checklist