Adding ShadowDOM Support
See original GitHub issueI have started working on adding ShadowDOM support to this shim (which we are using for our Polymer 2 application).
At first, nothing was working at all. ShadowDOM introduces event retargeting, so events that fire up through Shadow Roots have their target changed to be the parent of the highest shadow root. This introduces a problem for the tryFindDraggableTarget
function:
as event.target
no longer refers to the actual target of the event. I rewrote this method (in JS) as follows:
function tryFindDraggableTarget(event) {
for(var i = 0; i < event.path.length; i++) {
var el = event.path[i];
if(el.draggable === false) {
continue;
}
if (el.getAttribute && el.getAttribute("draggable") === "true") {
return el;
}
}
}
Success! I can now start drag operations successfully. Next up is dropping, which has proved to be more difficult. The code responsible for finding the drop target is here:
document.elementFromPoint
suffers a similar problem as before and returns only the highest shadow root rather than the actual element at the location. I found some documentation for DocumentOrShadowRoot.elementFromPoint(), but support for DocumentOrShadowRoot
seems limited at best. This is where I got stuck. Does anyone have any ideas on how to move forward from here?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:4
- Comments:28 (14 by maintainers)
I’m facing the same issue when using web components. Neither this polyfill nor https://github.com/Bernardo-Castilho/dragdroptouch/issues/25 is working when using ShadowDOM.
@timruffles Would love to see this feature merged 😎
I’ve shadow dom support workin on my system.
This is my workin Code: