Skip to content

Commit

Permalink
Refactor #4819
Browse files Browse the repository at this point in the history
  • Loading branch information
tugcekucukoglu committed Nov 15, 2023
1 parent e6b5cbd commit a073a66
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 21 deletions.
4 changes: 4 additions & 0 deletions components/lib/megamenu/BaseMegaMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export default {
type: String,
default: 'horizontal'
},
breakpoint: {
type: String,
default: '960px'
},
disabled: {
type: Boolean,
default: false
Expand Down
10 changes: 9 additions & 1 deletion components/lib/megamenu/MegaMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ export default {
focused: false,
focusedItemInfo: { index: -1, key: '', parentKey: '' },
activeItem: null,
dirty: false
dirty: false,
queryMatches: false
};
},
watch: {
Expand All @@ -74,6 +75,13 @@ export default {
},
mounted() {
this.id = this.id || UniqueComponentId();
const query = matchMedia(`(max-width: ${this.breakpoint})`);
this.queryMatches = query.matches;
query.addEventListener('change', () => {
this.queryMatches = query.matches;
});
},
beforeUnmount() {
this.unbindOutsideClickListener();
Expand Down
50 changes: 30 additions & 20 deletions components/lib/megamenu/style/MegaMenuStyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ const css = `
.p-megamenu-col-12 {
width: 100%;
}
.p-megamenu-mobile .p-megamenu-grid {
flex-wrap: wrap;
overflow: auto;
max-height: 90%;
}
}
`;

Expand All @@ -122,6 +128,7 @@ const classes = {
root: ({ instance }) => [
'p-megamenu p-component',
{
'p-megamenu-mobile': instance.queryMatches,
'p-megamenu-horizontal': instance.horizontal,
'p-megamenu-vertical': instance.vertical
}
Expand Down Expand Up @@ -153,26 +160,29 @@ const classes = {
let length = instance.isItemGroup(processedItem) ? processedItem.items.length : 0;
let columnClass;

switch (length) {
case 2:
columnClass = 'p-megamenu-col-6';
break;

case 3:
columnClass = 'p-megamenu-col-4';
break;

case 4:
columnClass = 'p-megamenu-col-3';
break;

case 6:
columnClass = 'p-megamenu-col-2';
break;

default:
columnClass = 'p-megamenu-col-12';
break;
if (instance.$parentInstance.queryMatches) columnClass = 'p-megamenu-col-12';
else {
switch (length) {
case 2:
columnClass = 'p-megamenu-col-6';
break;

case 3:
columnClass = 'p-megamenu-col-4';
break;

case 4:
columnClass = 'p-megamenu-col-3';
break;

case 6:
columnClass = 'p-megamenu-col-2';
break;

default:
columnClass = 'p-megamenu-col-12';
break;
}
}

return columnClass;
Expand Down

0 comments on commit a073a66

Please sign in to comment.