Make FocusTracker shadow dom aware

This commit is contained in:
Alex Dima 2021-11-24 13:42:54 +01:00
parent 556ce85c82
commit bb7a76bf2b
No known key found for this signature in database
GPG key ID: 39563C1504FDD0C9

View file

@ -939,9 +939,15 @@ class FocusTracker extends Disposable implements IFocusTracker {
private _refreshStateHandler: () => void;
private static hasFocusWithin(element: HTMLElement): boolean {
const shadowRoot = getShadowRoot(element);
const activeElement = (shadowRoot ? shadowRoot.activeElement : document.activeElement);
return isAncestor(activeElement, element);
}
constructor(element: HTMLElement | Window) {
super();
let hasFocus = isAncestor(document.activeElement, <HTMLElement>element);
let hasFocus = FocusTracker.hasFocusWithin(<HTMLElement>element);
let loosingFocus = false;
const onFocus = () => {
@ -966,7 +972,7 @@ class FocusTracker extends Disposable implements IFocusTracker {
};
this._refreshStateHandler = () => {
let currentNodeHasFocus = isAncestor(document.activeElement, <HTMLElement>element);
let currentNodeHasFocus = FocusTracker.hasFocusWithin(<HTMLElement>element);
if (currentNodeHasFocus !== hasFocus) {
if (hasFocus) {
onBlur();