Skip to content

Instantly share code, notes, and snippets.

@MarsiBarsi
Created July 14, 2020 13:30
Show Gist options
  • Save MarsiBarsi/bf3cefa9c0c128f630c101d168815c4c to your computer and use it in GitHub Desktop.
Save MarsiBarsi/bf3cefa9c0c128f630c101d168815c4c to your computer and use it in GitHub Desktop.
Returns current active element, including shadow dom
/**
* 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