pull/4823/head
tugcekucukoglu 2023-11-15 13:16:57 +03:00
parent e6b5cbd541
commit a073a6690a
3 changed files with 39 additions and 17 deletions

View File

@ -14,6 +14,10 @@ export default {
type: String, type: String,
default: 'horizontal' default: 'horizontal'
}, },
breakpoint: {
type: String,
default: '960px'
},
disabled: { disabled: {
type: Boolean, type: Boolean,
default: false default: false

View File

@ -55,7 +55,8 @@ export default {
focused: false, focused: false,
focusedItemInfo: { index: -1, key: '', parentKey: '' }, focusedItemInfo: { index: -1, key: '', parentKey: '' },
activeItem: null, activeItem: null,
dirty: false dirty: false,
queryMatches: false
}; };
}, },
watch: { watch: {
@ -74,6 +75,13 @@ export default {
}, },
mounted() { mounted() {
this.id = this.id || UniqueComponentId(); this.id = this.id || UniqueComponentId();
const query = matchMedia(`(max-width: ${this.breakpoint})`);
this.queryMatches = query.matches;
query.addEventListener('change', () => {
this.queryMatches = query.matches;
});
}, },
beforeUnmount() { beforeUnmount() {
this.unbindOutsideClickListener(); this.unbindOutsideClickListener();

View File

@ -111,6 +111,12 @@ const css = `
.p-megamenu-col-12 { .p-megamenu-col-12 {
width: 100%; width: 100%;
} }
.p-megamenu-mobile .p-megamenu-grid {
flex-wrap: wrap;
overflow: auto;
max-height: 90%;
}
} }
`; `;
@ -122,6 +128,7 @@ const classes = {
root: ({ instance }) => [ root: ({ instance }) => [
'p-megamenu p-component', 'p-megamenu p-component',
{ {
'p-megamenu-mobile': instance.queryMatches,
'p-megamenu-horizontal': instance.horizontal, 'p-megamenu-horizontal': instance.horizontal,
'p-megamenu-vertical': instance.vertical 'p-megamenu-vertical': instance.vertical
} }
@ -153,6 +160,8 @@ const classes = {
let length = instance.isItemGroup(processedItem) ? processedItem.items.length : 0; let length = instance.isItemGroup(processedItem) ? processedItem.items.length : 0;
let columnClass; let columnClass;
if (instance.$parentInstance.queryMatches) columnClass = 'p-megamenu-col-12';
else {
switch (length) { switch (length) {
case 2: case 2:
columnClass = 'p-megamenu-col-6'; columnClass = 'p-megamenu-col-6';
@ -174,6 +183,7 @@ const classes = {
columnClass = 'p-megamenu-col-12'; columnClass = 'p-megamenu-col-12';
break; break;
} }
}
return columnClass; return columnClass;
}, },