mirror of
https://github.com/shoelace-style/webawesome.git
synced 2026-01-12 04:09:12 +00:00
Tab Group - set active tab when element is visible (#154)
Another great catch. Thanks!
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user