Skip to content

Commit

Permalink
fix(#2109): tabs query preserve and load url-specified tab initially
Browse files Browse the repository at this point in the history
  • Loading branch information
syedszeeshan committed Dec 11, 2024
1 parent 11d0e76 commit b8d4c3c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
13 changes: 8 additions & 5 deletions libs/web-components/src/components/tabs/Tabs.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,17 @@
// Find the matching tab based on href
const tabs = _tabsEl?.querySelectorAll('[role="tab"]');
if (!tabs) return null;
for (let i = 0; i < tabs.length; i++) {
const tab = tabs[i] as HTMLAnchorElement;
if (
tab.getAttribute("href")?.endsWith(hash) ||
hash.endsWith(tab.getAttribute("href")?.split("#")[1] || "")
) {
const tabHref = tab.getAttribute("href");
const tabHash = tabHref?.split("#")[1] || "";
const isFullUrlMatch = tabHref?.endsWith(hash);
const isHashOnlyMatch = hash.endsWith(tabHash);
if (isFullUrlMatch || isHashOnlyMatch) {
return i + 1;
}
}
Expand Down
4 changes: 0 additions & 4 deletions libs/web-components/src/components/tabs/tabs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ describe("Tabs", () => {
const result = render(Tabs, { initialtab: 2 });

await waitFor(() => {
setTimeout(() => {
const tab1Link = result.container.querySelector("a#tab-1");
const tab2Link = result.container.querySelector("a#tab-2");
const tabPanel = result.container.querySelector("div[role=tabpanel]");
Expand All @@ -73,7 +72,6 @@ describe("Tabs", () => {

expect(goaTabs[0].getAttribute("open")).toBe("false");
expect(goaTabs[1].getAttribute("open")).toBe("true");
}, 1000);
});
});

Expand All @@ -82,11 +80,9 @@ describe("Tabs", () => {

// last tab
await waitFor(() => {
setTimeout(() => {
const tab = result.container.querySelector("a#tab-2");
expect(tab).toBeTruthy();
expect(tab?.getAttribute("aria-selected")).toBe("true");
}, 1000);
});
});

Expand Down

0 comments on commit b8d4c3c

Please sign in to comment.