@volo/ngx-lepton-x.core 5.0.0-rc.1 → 5.0.0-rc.2

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.
@@ -1552,9 +1552,8 @@ class NavbarRoutesComponent {
1552
1552
  if (!items?.length || !url) {
1553
1553
  return items;
1554
1554
  }
1555
- const updated = [...items];
1556
1555
  this.fixNavbarItems(url, items);
1557
- return updated;
1556
+ return items;
1558
1557
  });
1559
1558
  this.routerItem = input();
1560
1559
  this.routeClick = new EventEmitter();
@@ -1615,14 +1614,37 @@ class NavbarRoutesComponent {
1615
1614
  fixNavbarItems(currentUrl, items) {
1616
1615
  items.forEach((item) => {
1617
1616
  const { link, children } = item;
1617
+ const itemUrl = link?.split('?')[0];
1618
1618
  if (children?.length) {
1619
1619
  this.fixNavbarItems(currentUrl, children);
1620
- const hasActiveChild = children.some((child) => child.selected || child.expanded || child.link === currentUrl);
1621
- item.expanded ||= hasActiveChild || link === currentUrl;
1620
+ const hasActiveDescendant = this.hasActiveDescendant(children, currentUrl);
1621
+ const isInActiveChain = hasActiveDescendant || itemUrl === currentUrl;
1622
+ if (isInActiveChain) {
1623
+ item.expanded = true;
1624
+ }
1625
+ else {
1626
+ const hasExpandedChildren = children.some(child => child.expanded);
1627
+ if (!hasExpandedChildren) {
1628
+ item.expanded = false;
1629
+ }
1630
+ }
1631
+ item.selected = false;
1622
1632
  }
1623
1633
  else {
1624
- item.selected = link === currentUrl;
1634
+ item.selected = itemUrl === currentUrl;
1635
+ }
1636
+ });
1637
+ }
1638
+ hasActiveDescendant(items, currentUrl) {
1639
+ return items.some((item) => {
1640
+ const itemUrl = item.link?.split('?')[0];
1641
+ if (item.selected || itemUrl === currentUrl) {
1642
+ return true;
1643
+ }
1644
+ if (item.children?.length) {
1645
+ return this.hasActiveDescendant(item.children, currentUrl);
1625
1646
  }
1647
+ return false;
1626
1648
  });
1627
1649
  }
1628
1650
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.7", ngImport: i0, type: NavbarRoutesComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }