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 6, 2024
1 parent 11d0e76 commit 511d04f
Showing 1 changed file with 8 additions and 5 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

0 comments on commit 511d04f

Please sign in to comment.