Skip to content

Commit

Permalink
Fix#6415: Megamenu single array fix (primefaces#6416)
Browse files Browse the repository at this point in the history
* Fix#6415

* Update MegaMenu.js

* Update MegaMenu.js

---------

Co-authored-by: Melloware <[email protected]>
  • Loading branch information
Rekl0w and melloware authored Apr 18, 2024
1 parent baf3925 commit b4b17be
Showing 1 changed file with 24 additions and 21 deletions.
45 changes: 24 additions & 21 deletions components/lib/megamenu/MegaMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -738,26 +738,29 @@ export const MegaMenu = React.memo(
};

const createProcessedItems = (items, level = 0, parent = {}, parentKey = '', columnIndex) => {
const _processedItems = [];

items &&
items.forEach((item, index) => {
const key = (parentKey !== '' ? parentKey + '_' : '') + (columnIndex !== undefined ? columnIndex + '_' : '') + index;
const newItem = {
item,
index,
level,
key,
parent,
parentKey,
columnIndex: columnIndex !== undefined ? columnIndex : parent && parent.columnIndex !== undefined ? parent.columnIndex : index
};

newItem.items = level === 0 && item.items && item.items.length > 0 ? item.items.map((_items, _index) => createProcessedItems(_items, level + 1, newItem, key, _index)) : createProcessedItems(item.items, level + 1, newItem, key);
_processedItems.push(newItem);
});
if (!items) return [];

// #6415 if passed a single array[] instead of a matrix [][]
if (!Array.isArray(items)) {
items = [items];
}

return items.map((item, index) => {
const key = `${parentKey !== '' ? parentKey + '_' : ''}${columnIndex !== undefined ? columnIndex + '_' : ''}${index}`;
const newItem = {
item,
index,
level,
key,
parent,
parentKey,
columnIndex: columnIndex !== undefined ? columnIndex : parent && parent.columnIndex !== undefined ? parent.columnIndex : index
};

newItem.items = level === 0 && item.items && item.items.length > 0 ? item.items.map((_items, _index) => createProcessedItems(_items, level + 1, newItem, key, _index)) : createProcessedItems(item.items, level + 1, newItem, key);

return _processedItems;
return newItem;
});
};

const createSeparator = (index) => {
Expand Down Expand Up @@ -1054,7 +1057,7 @@ export const MegaMenu = React.memo(
.p-megamenu[${selector}] .p-menuitem > .p-menuitem-content > .p-menuitem-link > .p-submenu-icon {
margin-left: auto;
}
.p-megamenu[${selector}] .p-submenu-list .p-menuitem-content .p-menuitem-link {
padding-left: 2.25rem;
}
Expand All @@ -1071,7 +1074,7 @@ export const MegaMenu = React.memo(
${
vertical
? `
? `
.p-megamenu[${selector}] .p-menuitem > .p-menuitem-content > .p-menuitem-link > .p-submenu-icon {
transform: rotate(90deg);
}
Expand Down

0 comments on commit b4b17be

Please sign in to comment.