Fixes #148 - prevents recursive calls to observer

Uses a block list for the attributes that shouldn't trigger the observer. It may be better to use an allow list since the observer is still called unnecessarily for e.g. `style` attribute changes.
pull/149/head
Chris Haynes 2020-07-30 22:27:43 +01:00
rodzic c1300ea3d6
commit 8f0c1eb339
1 zmienionych plików z 9 dodań i 1 usunięć

Wyświetl plik

@ -59,7 +59,15 @@ export class TabGroup {
focusVisible.observe(this.tabGroup);
// Update aria labels if the DOM changes
this.mutationObserver = new MutationObserver(() => setTimeout(() => this.setAriaLabels()));
this.mutationObserver = new MutationObserver(mutations => {
if (
mutations.some(mutation => {
return !['arial-labeledby', 'aria-controls'].includes(mutation.attributeName);
})
) {
setTimeout(() => this.setAriaLabels());
}
});
this.mutationObserver.observe(this.host, { attributes: true, childList: true, subtree: true });
}