-
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
Reproduce github/primer#4027 #5207
base: main
Are you sure you want to change the base?
Conversation
|
size-limit report 📦
|
refs do not trigger effect to rerun
👋 Hi, this pull request contains changes to the source code that github/github depends on. If you are GitHub staff, we recommend testing these changes with github/github using the integration workflow. Thanks! |
Part 1: SelectPanel:
Video description:
reposition.mov
Not all that glitters...
Caveat: While the first part of the previous video looks like it's working perfectly, the panel only adjusts it's position once. So, if the length of the list changes again, for example while filtering, now the panel hangs awkwardly away from the anchor button.
far-away.mov
Part 2: AnchoredOverlay / useAnchoredPosition
This repositioning behavior comes from the underlying useAnchoredPosition hook and can be reproduced there as well:
The current behavior is implemented in AnchoredOverlay, but we may not want to change it for all AnchoredOverlays!
Part 3: When does an anchored overlay re-position itself?
This is the block of code that is of interest. to us:
https://github.com/primer/react/blob/main/packages/react/src/hooks/useAnchoredPosition.ts#L34-L48
So the position is re-calculate when
updatePosition
changes, that is when one offloatingElementRef
,anchorElementRef
ordepdencies
changes.a. As the first 2 dependencies are refs, they only change once when they are filled and not after that.
b. The dependencies list from AnchoredOverlay has
overlayRef.current
which changes twice, once when the ref is filled and again when the overlay is closedWhen the SelectPanel is opened near the bottom of the screen (like in left half of the video), it causes the height of the page to grow, triggering the resize observer.
In the right half of the video, SelectPanel is inside a dialog and there is no increase in page height and hence resize observer is not triggered. (The same would happen without a dialog as well if the page has overflow hidden, which is the case in memex)
Part 4: Potential fix
One potential fix is to add another resize observer that watches for changes in size of the floating element:
useResizeObserver(updatePosition) // default target element is document + useResizeObserver(updatePosition, floatingElementRef)
This does solve the solve the initial issue of the panel going out of screen, but trades it for a worse issue of constantly switching position when the size of the item changes 🤔
constant-switching.mov
A more complete fix is a more involved.
Notes from conversation with Maxime:
WIP PR: #5208
Related: Until now, there was no way to change anchorSide for select panel, there is however 4 instances that attempt it: 1 in dotcom and 3 in internal-statuspage