Allow passing in custom `getScrollParent`
See original GitHub issueIssue Description
Problem
getScrollParent
isn’t working correctly for my particular use case:
- My scroll container (
overflow-y
) is outside of my React app. - My React app isn’t mounted in the DOM yet when
getScrollParent
runs.
(We’re including the React app inside of a page written in a legacy framework. This problem occurs because of how we mount the React section of the page.)
Minimal working example
Fork of main example: https://codesandbox.io/s/x2kkkrjm8q
The relevant changes are:
- Move
.content-container
out of<Page>
and intoindex.html
. - Render
<Page>
into a div that isn’t in the DOM yet.
const div = document.createElement("div");
ReactDOM.render(<Page />, div);
const scrollContainer = document.querySelector(".content-container");
scrollContainer.appendChild(div);
Suggested solution
This is a pretty specific edge case that probably isn’t worth supporting in this library. That said, I’d like the ability to pass in a custom getScrollParent
implementation. Then I could do:
<StickyBox getScrollParent={() => document.getElementById('#scroll-container')}>
Issue Analytics
- State:
- Created 5 years ago
- Comments:5
Top Results From Across the Web
How to pass ref of component up three levels for scroll event?
The documentation says: getScrollParent Function Override method to return a different scroll listener if it's not the immediate parent of ...
Read more >Having troubles using custom state management, loadMore ...
I'm using a custom state management instead of using the page ... Fetch the items passing the "page" parameter from the state const...
Read more >react-windowed-list: Documentation | Openbase
A function that receives index and key and returns the content to be rendered for the item at that index. ... renderItem =...
Read more >Ext.dom.ButtonElement | Ext JS 6.2.0 - Sencha Documentation
Returns the offsets of this element from the passed element. The element must both be part of the DOM tree and not have...
Read more >https://www.ferris.edu/forms/js/popper.min.js.map
documentElement;\n }\n\n // Here we make sure to give as \"start\" the element that comes first ... getScrollParent';\nimport getBoundingClientRect from '.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Okay, makes sense. Two workarounds. Only mount StickyBox after
scrollContainer.appendChild
.You could use a component like this:
Or you do something like this:
Alright 😃