Skip to content

Commit

Permalink
Merge pull request #385 from conversionxl/anoblet/fix/navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelkmpt authored Jan 12, 2024
2 parents 3b7c176 + c44fa6e commit 7d9589a
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions packages/cxl-ui/src/components/cxl-marketing-nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,22 +88,7 @@ export class CXLMarketingNavElement extends LitElement {
* menu items last in the list by sorting the original this.groups array before
* flat map operation.
*/
@property({ type: Array })
get mobileGroups() {
// eslint-disable-next-line no-nested-ternary
const sorter = (a, b) => ('global' === a.name ? 1 : 'global' === b.name ? -1 : 0);
const groups = [...this.groups];
return [
{
name: 'primary',
items: groups
.sort(sorter)
.map((group) => group.items.filter((item) => !item.isSearch))
.flat(1),
},
];
}
@property({ type: Array }) mobileGroups = [];
get menuItemSearchElement() {
return this.querySelector('.search-button');
Expand All @@ -129,7 +114,6 @@ export class CXLMarketingNavElement extends LitElement {
});
requestAnimationFrame(() => {
this._updateContextMenuItems();
this._replaceMenuIcon();
this.initHeadroom();
});
Expand All @@ -140,6 +124,10 @@ export class CXLMarketingNavElement extends LitElement {
this._updateContextMenuItems();
this._replaceMenuIcon();
}
if (changes.has('groups')) {
this.mobileGroups = this.getMobileGroups();
}
}
render() {
Expand Down Expand Up @@ -442,4 +430,20 @@ export class CXLMarketingNavElement extends LitElement {

headroom.init();
}

getMobileGroups() {
// eslint-disable-next-line no-nested-ternary
const sorter = (a, b) => ('global' === a.name ? 1 : 'global' === b.name ? -1 : 0);
const groups = [...this.groups];

return [
{
name: 'primary',
items: groups
.sort(sorter)
.map((group) => group.items.filter((item) => !item.isSearch))
.flat(1),
},
];
}
}

0 comments on commit 7d9589a

Please sign in to comment.