Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/**
* @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