in src/focus.service.ts [257:291]
private triggerOnFocusHandlers(next: HTMLElement) {
if (!this.root) {
throw new Error('root not set');
}
const isAttached = this.selected !== null && this.root.contains(this.selected);
if (!isAttached) {
let elem: HTMLElement | null = next;
while (elem !== null && elem !== this.root) {
this.triggerFocusChange(elem, null);
elem = elem.parentElement;
}
return;
}
// Find the common ancestor of the next and currently selected element.
// Trigger focus changes on every element that we touch.
const common = getCommonAncestor(next, this.selected);
let el = this.selected;
while (el !== common && el !== null) {
this.triggerFocusChange(el, null);
el = el.parentElement;
}
el = next;
while (el !== common && el !== null) {
this.triggerFocusChange(el, null);
el = el.parentElement;
}
el = common;
while (el !== this.root && el !== null) {
this.triggerFocusChange(el, null);
el = el.parentElement;
}
}