Skip to content

Commit 7427b26

Browse files
authored
fix(overlay): outside click dispatcher not accounting for shadow DOM (#19904)
The outside click dispatcher was accessing the clicked element through `event.target` which won't work if the element is inside the shadow DOM.
1 parent 9ce2a90 commit 7427b26

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/cdk/overlay/dispatchers/overlay-outside-click-dispatcher.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ export class OverlayOutsideClickDispatcher extends BaseOverlayDispatcher {
6767

6868
/** Click event listener that will be attached to the body propagate phase. */
6969
private _clickListener = (event: MouseEvent) => {
70+
// Get the target through the `composedPath` if possible to account for shadow DOM.
71+
const target = event.composedPath ? event.composedPath()[0] : event.target;
7072
const overlays = this._attachedOverlays;
7173

7274
// Dispatch the mouse event to the top overlay which has subscribers to its mouse events.
@@ -81,7 +83,7 @@ export class OverlayOutsideClickDispatcher extends BaseOverlayDispatcher {
8183

8284
const config = overlayRef.getConfig();
8385
const excludeElements = [...config.excludeFromOutsideClick!, overlayRef.overlayElement];
84-
const isInsideClick: boolean = excludeElements.some(e => e.contains(event.target as Node));
86+
const isInsideClick: boolean = excludeElements.some(e => e.contains(target));
8587

8688
// If it is inside click just break - we should do nothing
8789
// If it is outside click dispatch the mouse event, and proceed with the next overlay

0 commit comments

Comments
 (0)