@abgov/web-components 1.17.0-alpha.130 → 1.17.0-alpha.131

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.js +26 -3
  2. package/index.js.map +1 -1
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -36044,6 +36044,7 @@ function instance$7($$self, $$props, $$invalidate) {
36044
36044
  let _currentTab = 1;
36045
36045
  let _tabProps = [];
36046
36046
  let _bindTimeoutId;
36047
+ let _initialLoad = true;
36047
36048
  onMount(() => {
36048
36049
  ensureSlotExists(_rootEl);
36049
36050
  addChildMountListener();
@@ -36052,6 +36053,22 @@ function instance$7($$self, $$props, $$invalidate) {
36052
36053
  onDestroy(() => {
36053
36054
  removeKeyboardEventListeners();
36054
36055
  });
36056
+ function getTabIndexFromHash() {
36057
+ const hash2 = window.location.hash;
36058
+ if (!hash2) return null;
36059
+ const tabs = _tabsEl == null ? void 0 : _tabsEl.querySelectorAll('[role="tab"]');
36060
+ for (let i = 0; i < tabs.length; i++) {
36061
+ const tab = tabs[i];
36062
+ const tabHref = tab.getAttribute("href");
36063
+ const tabHash = (tabHref == null ? void 0 : tabHref.split("#")[1]) || "";
36064
+ const isFullUrlMatch = tabHref == null ? void 0 : tabHref.endsWith(hash2);
36065
+ const isHashOnlyMatch = hash2.endsWith(tabHash);
36066
+ if (isFullUrlMatch || isHashOnlyMatch) {
36067
+ return i + 1;
36068
+ }
36069
+ }
36070
+ return null;
36071
+ }
36055
36072
  function addChildMountListener() {
36056
36073
  _rootEl.addEventListener("tab:mounted", (e) => {
36057
36074
  const detail = e.detail;
@@ -36062,7 +36079,11 @@ function instance$7($$self, $$props, $$invalidate) {
36062
36079
  _bindTimeoutId = setTimeout(
36063
36080
  () => {
36064
36081
  bindChildren();
36065
- setCurrentTab(initialtab || 1);
36082
+ if (_initialLoad) {
36083
+ const tabIndexFromHash = getTabIndexFromHash();
36084
+ setCurrentTab(tabIndexFromHash ?? (initialtab || 1));
36085
+ _initialLoad = false;
36086
+ }
36066
36087
  },
36067
36088
  1
36068
36089
  );
@@ -36071,6 +36092,7 @@ function instance$7($$self, $$props, $$invalidate) {
36071
36092
  }
36072
36093
  function bindChildren() {
36073
36094
  const path = window.location.pathname;
36095
+ const search = window.location.search;
36074
36096
  _tabProps.forEach((tabProps, index) => {
36075
36097
  let tabSlug = "";
36076
36098
  let headingEl;
@@ -36097,7 +36119,7 @@ function instance$7($$self, $$props, $$invalidate) {
36097
36119
  link.setAttribute("id", `tab-${index + 1}`);
36098
36120
  link.setAttribute("data-testid", `tab-${index + 1}`);
36099
36121
  link.setAttribute("role", "tab");
36100
- link.setAttribute("href", path + "#" + tabSlug);
36122
+ link.setAttribute("href", `${path}${search}#${tabSlug}`);
36101
36123
  link.addEventListener("click", () => setCurrentTab(index + 1));
36102
36124
  link.setAttribute("aria-controls", `tabpanel-${index + 1}`);
36103
36125
  link.appendChild(headingEl);
@@ -36146,7 +36168,8 @@ function instance$7($$self, $$props, $$invalidate) {
36146
36168
  _slotEl.setAttribute("aria-labelledby", `tab-${_currentTab}`);
36147
36169
  _slotEl.setAttribute("id", `tabpanel-${_currentTab}`);
36148
36170
  if (currentLocation) {
36149
- document.location = currentLocation;
36171
+ const url = new URL(currentLocation);
36172
+ history.pushState({}, "", url.pathname + url.search + url.hash);
36150
36173
  }
36151
36174
  }
36152
36175
  function handleKeydownEvents() {