Skip to main content

getComposedEventTarget

function

Returns the un-retargeted event target — the real element the user interacted with — for events observed by a listener above an enclosing DOM shadow root. `Event.target` is retargeted to the outermost shadow host in that case, hiding the actual element; `composedPath()[0]` returns the original target for `composed: true` events (most user-agent UI events: click, mousedown, pointerdown, focusin, etc.). Falls back to `event.target` when `composedPath` is unavailable or returns an empty array (e.g. the event has already finished dispatching). Pairs with the shadow-aware helpers above (getDOMSelectionPoints, getActiveElement) for the event side of the shadow boundary — useful when an `Element.contains(target)` check needs to test against an editor root inside a shadow tree.

function getComposedEventTarget(event: Event): EventTarget | null

Import

import { getComposedEventTarget } from '@modular/sdk/editor';

Notes

returns
The un-retargeted target, or null when the event has none.