Co-authored-by: Mikhail Bashkirov <mikhail.bashkirov@ing.com> Co-authored-by: Thijs Louisse <thijs.louisse@ing.com> Co-authored-by: Joren Broekema <joren.broekema@ing.com> Co-authored-by: Gerjan van Geest <gerjan.van.geest@ing.com> Co-authored-by: Erik Kroes <erik.kroes@ing.com> Co-authored-by: Lars den Bakker <lars.den.bakker@ing.com>
14 lines
431 B
JavaScript
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;
|
|
}
|