Files
2026-08-07 21:39:30 +02:00

14 lines
465 B
JavaScript

/**
* Returns the target element of an event, accounting for shadow DOM.
* @param event The event object.
* @returns The target element of the event.
*/
export function getTarget(event) {
if ('composedPath' in event) {
return event.composedPath()[0] ?? event.target;
}
// Fallback for environments where `composedPath` is not available.
// TS narrows `event` to `never` here because it assumes `composedPath` always exists.
return event.target;
}