@kodaris/krubble-app-components 1.0.39 → 1.0.41

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.
@@ -2240,9 +2240,23 @@ let KRScreenNav = class KRScreenNav extends i$1 {
2240
2240
  */
2241
2241
  this.navItems = [];
2242
2242
  /**
2243
- * Currently active item ID
2243
+ * Currently active item ID. Auto-detected from the URL by default.
2244
+ * Can be set explicitly by the parent to override.
2244
2245
  */
2245
2246
  this.activeId = '';
2247
+ this.handlePopstate = () => {
2248
+ this.syncActiveFromUrl();
2249
+ };
2250
+ }
2251
+ connectedCallback() {
2252
+ super.connectedCallback();
2253
+ // Defer so property bindings (.navItems) have been applied
2254
+ requestAnimationFrame(() => this.syncActiveFromUrl());
2255
+ window.addEventListener('popstate', this.handlePopstate);
2256
+ }
2257
+ disconnectedCallback() {
2258
+ super.disconnectedCallback();
2259
+ window.removeEventListener('popstate', this.handlePopstate);
2246
2260
  }
2247
2261
  /**
2248
2262
  * Handles click events on navigation items.
@@ -2271,6 +2285,24 @@ let KRScreenNav = class KRScreenNav extends i$1 {
2271
2285
  if (navEvent.defaultPrevented) {
2272
2286
  e.preventDefault();
2273
2287
  }
2288
+ this.activeId = item.id;
2289
+ }
2290
+ syncActiveFromUrl() {
2291
+ const pathname = window.location.pathname;
2292
+ const match = this.navItems.find((item) => {
2293
+ if (!item.url) {
2294
+ return false;
2295
+ }
2296
+ // Absolute URL — exact match
2297
+ if (item.url.startsWith('/')) {
2298
+ return pathname === item.url;
2299
+ }
2300
+ // Relative URL — match against the end of the pathname
2301
+ return pathname.endsWith('/' + item.url);
2302
+ });
2303
+ if (match) {
2304
+ this.activeId = match.id;
2305
+ }
2274
2306
  }
2275
2307
  render() {
2276
2308
  return b `