@triptease/tt-navbar 0.0.33 → 0.0.35

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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @triptease/tt-navbar v0.0.33
2
+ * @triptease/tt-navbar v0.0.35
3
3
  */
4
4
 
5
5
  // src/urlMappings.ts
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Webcomponent tt-navbar following open-wc recommendations",
4
4
  "license": "MIT",
5
5
  "author": "tt-navbar",
6
- "version": "0.0.33",
6
+ "version": "0.0.35",
7
7
  "type": "module",
8
8
  "main": "dist/src/index.js",
9
9
  "module": "dist/src/index.js",
package/src/TtNavbar.ts CHANGED
@@ -67,14 +67,19 @@ export class TtNavbar extends LitElement {
67
67
  }
68
68
 
69
69
  public connectedCallback() {
70
-
70
+ // Listen for browser back/forward navigation
71
71
  window.addEventListener('popstate', this.setActiveState);
72
+
73
+ // Listen for Tetris programmatic navigation
74
+ window.addEventListener('tetris:navigate', this.setActiveState);
75
+
72
76
  super.connectedCallback();
73
77
  }
74
78
 
75
79
  public disconnectedCallback() {
76
-
77
80
  window.removeEventListener('popstate', this.setActiveState);
81
+ window.removeEventListener('tetris:navigate', this.setActiveState);
82
+
78
83
  super.disconnectedCallback();
79
84
  }
80
85
 
@@ -141,6 +146,12 @@ export class TtNavbar extends LitElement {
141
146
  if (bestMatch) {
142
147
  bestMatch.classList.add('current-page');
143
148
  bestMatch.setAttribute('aria-current', 'page');
149
+
150
+ // Auto-expand parent details if the active link is within a collapsible section
151
+ const parentDetails = bestMatch.closest('details');
152
+ if (parentDetails) {
153
+ parentDetails.setAttribute('open', '');
154
+ }
144
155
  } else {
145
156
  console.error(`No matching nav link found for path: ${currentPath}`);
146
157
  }
@@ -345,4 +345,39 @@ describe('TtNavbar', () => {
345
345
  await expect(getComputedStyle(navbar).getPropertyValue('--nav-bar-width').trim()).to.equal('fit-content');
346
346
 
347
347
  });
348
+
349
+ it('should expand the details when the current page is within that section', async () => {
350
+ // eslint-disable-next-line no-restricted-globals
351
+ history.pushState({}, '', `/parity/${CLIENT_KEY}`);
352
+
353
+ const navbar = await fixture<TtNavbar>(
354
+ `<tt-navbar client-key=${CLIENT_KEY}></tt-navbar>`
355
+ );
356
+
357
+ const marketInsightsDetails = navbar.shadowRoot!.querySelector('#market-insights') as HTMLDetailsElement;
358
+
359
+ expect(marketInsightsDetails).to.exist;
360
+ expect(marketInsightsDetails.open).to.be.true;
361
+ })
362
+
363
+ it('should set the active route when receives `tetris:navigate` event', async () => {
364
+ const navbar = await fixture<TtNavbar>(
365
+ `<tt-navbar client-key=${CLIENT_KEY}></tt-navbar>`
366
+ );
367
+ // eslint-disable-next-line no-restricted-globals
368
+ history.pushState({}, '', `/account/billing-management/${CLIENT_KEY}`)
369
+
370
+
371
+ // Dispatch the event to change to Channels route
372
+ const navigateEvent = new CustomEvent('tetris:navigate', {
373
+ });
374
+ window.dispatchEvent(navigateEvent);
375
+
376
+ await elementUpdated(navbar);
377
+ const anchor = navbar.shadowRoot!.querySelector('a[aria-current="page"]');
378
+
379
+ expect(anchor).to.exist;
380
+ expect(anchor!.textContent).to.include('Booking reconciliation');
381
+
382
+ })
348
383
  });