From 1cf4741b2be708289bf73518443d2b2a41517d00 Mon Sep 17 00:00:00 2001 From: mmuehlich <32823494+mmuehlich@users.noreply.github.com> Date: Fri, 18 Apr 2025 09:36:04 +0000 Subject: [PATCH] Set composed and composedPath() for Events within shadow DOM --- ts/drag-drop-touch-util.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/ts/drag-drop-touch-util.ts b/ts/drag-drop-touch-util.ts index 0f1457f..d9ad5ae 100644 --- a/ts/drag-drop-touch-util.ts +++ b/ts/drag-drop-touch-util.ts @@ -59,6 +59,7 @@ export function newForwardableEvent( const evt = new Event(type, { bubbles: true, cancelable: true, + composed: target.shadowRoot?.mode === "open", }) as unknown as Mutable & { readonly defaultPrevented: boolean; }, @@ -68,6 +69,19 @@ export function newForwardableEvent( copyProps(evt, srcEvent, _kbdProps); copyProps(evt, touch, _ptProps); setOffsetAndLayerProps(evt, target); + // set composedPath for shadow DOM + if (evt.composed) { + evt.composedPath = () => { + const pt = pointFrom(srcEvent); + const el = target.shadowRoot?.elementFromPoint(pt.x, pt.y); + const getPath = (e?: Element | null, path: Element[] = []) => { + if (!e) return path; + path.unshift(e); + return getPath(e.parentElement, path); + }; + return getPath(el); + }; + } return evt; }