Created
July 14, 2020 13:30
-
-
Save MarsiBarsi/bf3cefa9c0c128f630c101d168815c4c to your computer and use it in GitHub Desktop.
Returns current active element, including shadow dom
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Returns current active element, including shadow dom | |
* | |
* @return element or null | |
*/ | |
export function getNativeFocused(documentRef: Document): Element | null { | |
if (!documentRef.activeElement || !documentRef.activeElement.shadowRoot) { | |
return documentRef.activeElement; | |
} | |
let element = documentRef.activeElement.shadowRoot.activeElement; | |
while (element && element.shadowRoot) { | |
element = element.shadowRoot.activeElement; | |
} | |
return element; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment