Open benjaco opened 7 years ago
It doesn't work inside a shadow dom element, because document.activeElement will select the most outer custom element insted of the input.
Googles own "back-to-backspace" uses "var target = event.path[0];" to get the correct element, it works even inside a shadow element.
Another more hack'y way to do it is to check if it is a shadow element, and look inside of it if it is (this code is not fully tested)
function getFocusElement() { var focusedElement = document.activeElement; var focusShadowDomElement; if (focusedElement == null) { return false; } while (focusedElement.shadowRoot !== null) { focusShadowDomElement = focusedElement.shadowRoot.activeElement; if (focusShadowDomElement == null) { break; } else { focusedElement = focusShadowDomElement; } } return focusedElement; }
It doesn't work inside a shadow dom element, because document.activeElement will select the most outer custom element insted of the input.
Googles own "back-to-backspace" uses "var target = event.path[0];" to get the correct element, it works even inside a shadow element.
Another more hack'y way to do it is to check if it is a shadow element, and look inside of it if it is (this code is not fully tested)
19 Is related to this issue