lion/packages/ui/components/overlays/utils/get-deep-active-element.js
2022-10-31 16:55:07 +01:00

14 lines
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;
}