Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(component): fix tab isolation in nested post-tabs component (cherry pick #4211 to v7) #4216

Open
wants to merge 1 commit into
base: release/v7
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -20,9 +20,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 =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you update the query selector with the solution you use in #4214?

tab.closest('post-tabs') === this.host
);
}

@Element() host: HTMLPostTabsElement;

Expand All @@ -44,7 +46,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 @@ -127,7 +129,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
Loading