@salesforcedevs/docs-components 1.3.325-rnbtab-alpha → 1.3.325-rnbtab-alpha1

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforcedevs/docs-components",
3
- "version": "1.3.325-rnbtab-alpha",
3
+ "version": "1.3.325-rnbtab-alpha1",
4
4
  "description": "Docs Lightning web components for DSC",
5
5
  "license": "MIT",
6
6
  "main": "index.js",
@@ -128,16 +128,13 @@ export default class ContentLayout extends LightningElement {
128
128
  let headingElements = document.querySelectorAll(TOC_HEADER_TAG);
129
129
  if (this.showTabBasedRNB) {
130
130
  const tabPanelListItem: any = this.selectTabElement();
131
- // for (const tabPanelListItem of tabPanelListItems) {
132
- if (tabPanelListItem.id === RNB_BY_TAB) {
133
- const tabPanels =
134
- tabPanelListItem.querySelectorAll("dx-tab-panel");
135
- for (const tabPanelItem of tabPanels) {
136
- if (tabPanelItem.active) {
137
- headingElements =
138
- tabPanelItem.querySelectorAll(TOC_HEADER_TAG);
139
- break;
140
- }
131
+ const tabPanels =
132
+ tabPanelListItem?.querySelectorAll("dx-tab-panel");
133
+ for (const tabPanelItem of tabPanels) {
134
+ if (tabPanelItem.active) {
135
+ headingElements =
136
+ tabPanelItem.querySelectorAll(TOC_HEADER_TAG);
137
+ break;
141
138
  }
142
139
  }
143
140
  }
@@ -146,66 +143,24 @@ export default class ContentLayout extends LightningElement {
146
143
 
147
144
  private updateURL() {
148
145
  const tabPanelListItem: any = this.selectTabElement();
149
- if (tabPanelListItem?.id === RNB_BY_TAB) {
150
- const tabPanelItems: any =
151
- tabPanelListItem?.shadowRoot.querySelectorAll(
146
+ if (tabPanelListItem?.shadowRoot) {
147
+ const tabPanelItems =
148
+ tabPanelListItem.shadowRoot.querySelectorAll(
152
149
  "dx-tab-panel-item"
153
150
  );
154
151
  if (tabPanelItems) {
155
- for (const tabPanelItem of tabPanelItems as any) {
152
+ tabPanelItems.forEach((tabPanelItem: any) => {
156
153
  const tab = tabPanelItem.shadowRoot.querySelector("button");
157
- const url = new URL(window.location.href);
158
- const previousTabID = url.searchParams.get("type");
159
- const tabID = tab?.getAttribute("aria-label");
160
- if (
161
- tab?.getAttribute("aria-selected") === "true" &&
162
- previousTabID !== tabID
163
- ) {
164
- url.searchParams.set("type", tabID);
165
- url.hash = "";
166
- window.history.pushState({}, "", url.toString());
167
- break;
168
- }
169
- }
170
- }
171
- }
172
- }
173
-
174
- private tabOnPageLoad() {
175
- const url = new URL(window.location.href);
176
- const previousTabID = url.searchParams.get("type");
177
-
178
- if (!previousTabID) {
179
- this.updateURL();
180
- } else {
181
- const tabPanelListItem: any = this.selectTabElement();
182
- const tabPanelItems: any =
183
- tabPanelListItem?.shadowRoot.querySelectorAll(
184
- "dx-tab-panel-item"
185
- );
186
- const tabPanels = tabPanelListItem.querySelectorAll("dx-tab-panel");
187
- if (tabPanelItems) {
188
- let tabIndex = 0;
189
- for (const tabPanelItem of tabPanelItems as any) {
190
- const tab = tabPanelItem.shadowRoot.querySelector("button");
191
- const activeTab =
192
- tabPanels[tabIndex]?.shadowRoot.querySelector(
193
- ".tabpanel"
194
- );
195
- if (tab?.getAttribute("aria-label") === previousTabID) {
196
- if (activeTab) {
197
- activeTab.classList.add("tabpanel-active");
154
+ if (tab?.getAttribute("aria-selected") === "true") {
155
+ const tabID = tab?.getAttribute("aria-label");
156
+ const url = new URL(window.location.href);
157
+ if (url.searchParams.get("type") !== tabID) {
158
+ url.searchParams.set("type", tabID);
159
+ url.hash = "";
160
+ window.history.pushState({}, "", url.toString());
198
161
  }
199
- tab.active = true;
200
- this.initialIndex = tabIndex;
201
- } else {
202
- if (activeTab) {
203
- activeTab.classList.remove("tabpanel-active");
204
- }
205
- tab.active = false;
206
162
  }
207
- tabIndex++;
208
- }
163
+ });
209
164
  }
210
165
  }
211
166
  }
@@ -260,10 +215,40 @@ export default class ContentLayout extends LightningElement {
260
215
 
261
216
  if (this.showTabBasedRNB) {
262
217
  window.addEventListener("tabchanged", this.onTabChanged);
263
- this.tabOnPageLoad();
218
+ this.restoreTabSelection();
264
219
  }
265
220
  }
266
221
 
222
+ private restoreTabSelection() {
223
+ const urlParams = new URLSearchParams(window.location.search);
224
+ const selectedTabId = urlParams.get("type");
225
+
226
+ if (selectedTabId) {
227
+ this.selectTabById(selectedTabId);
228
+ }
229
+ }
230
+
231
+ private selectTabById(tabId: string) {
232
+ requestAnimationFrame(() => {
233
+ const tabPanelListItem: any = this.selectTabElement();
234
+ if (tabPanelListItem?.shadowRoot) {
235
+ const tabPanelItems =
236
+ tabPanelListItem.shadowRoot.querySelectorAll(
237
+ "dx-tab-panel-item"
238
+ );
239
+ if (tabPanelItems) {
240
+ tabPanelItems.forEach((tabPanelItem: any) => {
241
+ const tab =
242
+ tabPanelItem.shadowRoot.querySelector("button");
243
+ if (tab?.getAttribute("aria-label") === tabId) {
244
+ tab?.click();
245
+ }
246
+ });
247
+ }
248
+ }
249
+ });
250
+ }
251
+
267
252
  renderedCallback(): void {
268
253
  /**
269
254
  * Note: We are adding timeout because chrome is optimizing and not triggering recent renderedCallback though elements reference is changed
@@ -439,7 +424,12 @@ export default class ContentLayout extends LightningElement {
439
424
 
440
425
  // Note: We are doing document.querySelectorAll as a quick fix as we are not getting heading elements reference this.querySelectorAll
441
426
  const headingElements = this.getHeadingElements();
442
- this.updateURL();
427
+
428
+ // We only need to update URL in case of /docs and ignore if tabs are used anywhere else in DSC
429
+ if (this.showTabBasedRNB) {
430
+ this.updateURL();
431
+ }
432
+
443
433
  for (const headingElement of headingElements as any) {
444
434
  // Add headingElements to intersectionObserver for highlighting respective RNB item when user scroll
445
435
  const id = headingElement.getAttribute("id")!;