-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Initial proposal to support usage in shadow roots #2264
Conversation
This change is a rough and initial proposal allowing to use this library at least within the same parent shadow root (but not cross shadowRoots yet). It does neither cover all functionalities yet nor is in a quality state to be merged (missing tests etc). This requires the following aspects - Make sure not using query selectors on document directly as those cannot find elements inside shadow roots. Therefore use specific DOM nodes to start searching other nodes - Events are handled centrally, but event.target will reference to the hosting element. Therefore use event.composedPath() to get the real nested element for that event. - Shadow roots isolate stylesheets, means global styles do not bleed into the shadow root. Therefore we need to make sure to generate the styles into the shadow root. As I couldn't find a way to get the mounted DOM node for the DragDropContext component at the point in time where the stylesheets are currently getting generated into the DOM. Therefore this changes allows consumers to specify the DOM location as a prop of the DragDropContext. Same approach is taken by JSS (see https://cssinjs.org/jss-api?v=v10.6.0#setup-jss-instance).
Thank you for your submission! Like many open source projects, we ask that you sign our CLA (Contributor License Agreement) before we can accept your contribution. Already signed the CLA? To re-check, try refreshing the page. |
Thanks @mrbaguvix, |
You can create an issue to this effect maybe the community can better reproduce this. |
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 a lot for the change! It works now for my use case inside shadowRoot, with a minor change mentioned below :)
@@ -171,7 +171,7 @@ function tryStart({ | |||
return null; | |||
} | |||
|
|||
const entry: DraggableEntry = registry.draggable.getById(draggableId); | |||
const entry: DraggableEntry = registry.draggable.getById(draggableId, sourceEvent.srcElement.shadowRoot || document); | |||
const el: ?HTMLElement = findDraggable(contextId, entry.descriptor.id); |
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.
You added a param "documentFragment" to findDraggable but the caller does not pass in the argument. Change it to findDraggable(contextId, entry.descriptor.id, sourceEvent.srcElement.shadowRoot || document) works for me
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 @kehengz, uploaded an additional commit which also fixes this part. The first commit was more of a hacky sketch.
Out of curiosity, did you tested with React 17 or lower?
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.
Got it thanks! My repo uses React 17
- Clean-up former commit - Adapted more places to work with shadowRoots - Introduced helper functions for querying elements - Support for nested shadowRoots - Added sample stories
422e522
to
acdea5b
Compare
b337f7d
to
3b787f3
Compare
3b787f3
to
71fec43
Compare
hey @spielzeugland, we've received your signed CLA. It's just mapped to a different github username (BobPfeiffer?). @danieldelcore (or other maintainers) feel free to merge this while we get @spielzeugland's entry in our db updated to the correct github account 🙂. |
Thanks @gorakong and @mrbaguvix for your support - I should have marked this PR as a draft. There is still one TODO left in query-elements.js which I want to address. Probably I should also add some tests before merging? |
@mrbaguvix I think I am done with the change now. Would be great if you could review it again. As said I worked on allowing shadow roots inside draggables/droppables, added some tests and samples. |
@spielzeugland I've played a bit with your changes - great work, thank you very much for it! One small fix, in src/view/use-style-marshal/get-styles.js . There are styles that are supposed to be applied globally using |
This solves the problem of missing drop events in sample stories.
Thanks @Nuurek, for the trying out and suggesting a fix. I uploaded the changes. |
Hi @danieldelcore, Hi @alexreardon, |
This fixes missing grabbing cursor while dragging.
3a69274
to
f7d361a
Compare
Moved to a new PR #2319 with rewritten history in order to satisfy the CLA build. |
This change is a rough and initial proposal allowing to use this
library at least within the same parent shadow root #1659 (but not cross
shadowRoots yet). It does neither cover all functionalities yet nor
is in a quality state to be merged (missing tests etc).
This requires the following aspects
cannot find elements inside shadow roots. Therefore use specific DOM
nodes to start searching other nodes
hosting element. Therefore use event.composedPath() to get the real
nested element for that event.
into the shadow root. Therefore we need to make sure to generate the
styles into the shadow root. As I couldn't find a way to get the
mounted DOM node for the DragDropContext component at the point in
time where the stylesheets are currently getting generated into the
DOM. Therefore this changes allows consumers to specify the DOM
location as a prop of the DragDropContext. Same approach is taken by
JSS (see https://cssinjs.org/jss-api?v=v10.6.0#setup-jss-instance).