kopia lustrzana https://github.com/shoelace-style/shoelace
Tab Group - set active tab when element is visible (#154)
Another great catch. Thanks!pull/157/head
rodzic
887bfb258b
commit
b51871aca3
|
@ -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
|
||||
|
|
Ładowanie…
Reference in New Issue