Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/cdk/platform/features/shadow-dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,14 @@ export function _getFocusedElementPierceShadowDom(): HTMLElement | null {

/** Gets the target of an event while accounting for Shadow DOM. */
export function _getEventTarget<T extends EventTarget>(event: Event): T | null {
// If an event is bound outside the Shadow DOM, the `event.target` will
// point to the shadow root so we have to use `composedPath` instead.
return (event.composedPath ? event.composedPath()[0] : event.target) as T | null;
// If an event is bound outside the Shadow DOM, the `event.target` will point to the shadow root
// so we have to use `composedPath` instead. Note that `composedPath` can throw if it's called
// during event replay (see #33386).
// TODO(crisbeto): it seems like `preventDefault` throws during replay as well.
if (event.composedPath) {
try {
return event.composedPath()[0] as T | null;
} catch {}
}
return event.target as T | null;
}
Loading