Tab Group - set active tab when element is visible (#154)

Another great catch. Thanks!
pull/157/head
Chris Haynes 2020-08-02 11:49:47 +01:00 zatwierdzone przez GitHub
rodzic 887bfb258b
commit b51871aca3
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
1 zmienionych plików z 10 dodań i 3 usunięć

Wyświetl plik

@ -53,9 +53,16 @@ export class TabGroup {
}
componentDidLoad() {
// Set initial tab state
this.setAriaLabels();
this.setActiveTab(this.getActiveTab() || this.getAllTabs()[0], false);
// Set initial tab state when the tabs first become visible
const observer = new IntersectionObserver((entries, observer) => {
if (entries[0].intersectionRatio > 0) {
this.setAriaLabels();
this.setActiveTab(this.getActiveTab() || this.getAllTabs()[0], false);
observer.unobserve(entries[0].target);
}
});
observer.observe(this.host);
focusVisible.observe(this.tabGroup);
// Update aria labels if the DOM changes