Skip to content

Commit

Permalink
fix(component): fix tab isolation in nested post-tabs component (#4211
Browse files Browse the repository at this point in the history
)
  • Loading branch information
alionazherdetska committed Dec 12, 2024
1 parent 8eb568d commit 1b6716c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/gorgeous-glasses-end.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@swisspost/design-system-components': patch
---

Fix tab isolation in nested `post-tabs` components by scoping tab queries and interactions to the current instance.
12 changes: 7 additions & 5 deletions packages/components/src/components/post-tabs/post-tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ export class PostTabs {
private hiding: Animation;
private isLoaded = false;

private get tabs(): NodeListOf<HTMLPostTabHeaderElement> {
return this.host.querySelectorAll('post-tab-header');
}
private get tabs(): HTMLPostTabHeaderElement[] {
return Array.from(this.host.querySelectorAll<HTMLPostTabHeaderElement>('post-tab-header')).filter(tab =>
tab.closest('post-tabs') === this.host
);
}

@Element() host: HTMLPostTabsElement;

Expand All @@ -45,7 +47,7 @@ export class PostTabs {
this.moveMisplacedTabs();
this.enableTabs();

const initiallyActivePanel = this.activePanel || this.tabs.item(0).panel;
const initiallyActivePanel = this.activePanel || this.tabs[0]?.panel;
void this.show(initiallyActivePanel);

this.isLoaded = true;
Expand Down Expand Up @@ -128,7 +130,7 @@ export class PostTabs {

// if the currently active tab was removed from the DOM then select the first one
if (this.activeTab && !this.activeTab.isConnected) {
void this.show(this.tabs.item(0).panel);
void this.show(this.tabs[0]?.panel);
}
}

Expand Down

0 comments on commit 1b6716c

Please sign in to comment.