Closed aearly closed 11 months ago
Thanks! Makes sense and looks good.
Ran into this in tests... it might be though because of events being created outside of the DOM... so they don't have the full DOM API available
process unhandled rejection TypeError: ev.composedPath is not a function
I'll do a commit for this right now, would be good to change too:
export interface EventPrototype {
target: ElementPrototype;
composedPath?(): ElementPrototype[];
defaultPrevented: unknown;
submitter: Record<string, unknown>;
}
And use, assuming too that it could be possible to get no values returned as well (maybe if its a CustomEvent, has composedPath but isn't populated somehow?):
function getComposedPathTarget(event: EventPrototype) {
if (!event.composedPath) {
return event.target;
}
const targets = event.composedPath();
return targets[0] ?? event.target;
}
Fixes #14.
ev.composedPath()[0]
rather thanev.target
to find links.ev.target
will only be the containing web component -- it doesn't cross shadow DOM boundaries.Checklist
yarn build