Skip to content

Instantly share code, notes, and snippets.

@samthor
Created August 14, 2020 00:55
Show Gist options
  • Save samthor/34e3ef00bdcecf6dc7cbc8738fb4524f to your computer and use it in GitHub Desktop.
Save samthor/34e3ef00bdcecf6dc7cbc8738fb4524f to your computer and use it in GitHub Desktop.
/**
* @param {!Element=}
* @return {!Array<!Element>} containing focused element, deepest first
*/
function getActive(t = document.activeElement || document.body) {
if (t.activeElement) {
t = t.activeElement;
}
if (t.shadowRoot) {
return [...getActive(t.shadowRoot), t];
}
return [t];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment