@lion/ui
Version:
A package of extendable web components
15 lines (14 loc) • 431 B
JavaScript
/**
* Returns the activeElement, even when they are inside a shadowRoot.
* (If an element in a shadowRoot is focused, document.activeElement
* returns the shadowRoot host.
*
* @returns {Element}
*/
export function getDeepActiveElement() {
let host = document.activeElement || document.body;
while (host && host.shadowRoot && host.shadowRoot.activeElement) {
host = host.shadowRoot.activeElement;
}
return host;
}