Fix bounds="selector" functionality when in a Shadow DOM tree. #763
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi! I'm Miguel Calderón and work at PSPDFKit. I'd like to say thanks for your package, which is great!
We've recently switched our SDK container from Iframe to Shadow DOM, and are about to upgrade to React 18, which is bringing up lots of small headaches, mostly caused by our own tech debt.
One of the problems we're finding is using
react-draggable
from within the Shadow DOM when setting thebounds
prop to a selector.Details
The
bounds
prop was not working correctly when set to a selector within a Shadow DOM tree. The reason is that the provided selector was being queried toownerDocument
and would throw if the node was attached within a Shadow root.Here's an example showing the problem: https://playcode.io/1996274
withShadow
tofalse
it will work.The solution applied in this PR is to query the node returned by
node.getRootNode()
instead: this method returnsownerDocument
when called on the normal DOM as before, but when the node is inside a Shadow root, the shadow root will be returned instead. Additionally, if the node is inside a fragment and not attached to a document nor a Shadow root, the topmost element will be returned.Some tests have been added as well to cover
bounds
asparent
as selector, from within a Shadow root and in the normal DOM.