Skip to content

Commit

Permalink
Fixed #6522 - For TieredMenu
Browse files Browse the repository at this point in the history
  • Loading branch information
tugcekucukoglu committed Oct 4, 2024
1 parent ee1b626 commit 0c57108
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 3 deletions.
4 changes: 4 additions & 0 deletions packages/primevue/src/tieredmenu/BaseTieredMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ export default {
type: [String, Object],
default: 'body'
},
breakpoint: {
type: String,
default: '960px'
},
autoZIndex: {
type: Boolean,
default: true
Expand Down
5 changes: 5 additions & 0 deletions packages/primevue/src/tieredmenu/TieredMenu.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,11 @@ export interface TieredMenuProps {
* @defaultValue false
*/
popup?: boolean | undefined;
/**
* The breakpoint to define the maximum width boundary.
* @defaultValue 960px
*/
breakpoint?: string | undefined;
/**
* A valid query selector or an HTMLElement to specify where the overlay gets attached.
* @defaultValue body
Expand Down
27 changes: 26 additions & 1 deletion packages/primevue/src/tieredmenu/TieredMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export default {
inheritAttrs: false,
emits: ['focus', 'blur', 'before-show', 'before-hide', 'hide', 'show'],
outsideClickListener: null,
matchMediaListener: null,
scrollHandler: null,
resizeListener: null,
target: null,
Expand All @@ -72,7 +73,9 @@ export default {
activeItemPath: [],
visible: !this.popup,
submenuVisible: false,
dirty: false
dirty: false,
query: null,
queryMatches: false
};
},
watch: {
Expand All @@ -93,10 +96,12 @@ export default {
},
mounted() {
this.id = this.id || UniqueComponentId();
this.bindMatchMediaListener();
},
beforeUnmount() {
this.unbindOutsideClickListener();
this.unbindResizeListener();
this.unbindMatchMediaListener();
if (this.scrollHandler) {
this.scrollHandler.destroy();
Expand Down Expand Up @@ -498,6 +503,26 @@ export default {
this.resizeListener = null;
}
},
bindMatchMediaListener() {
if (!this.matchMediaListener) {
const query = matchMedia(`(max-width: ${this.breakpoint})`);
this.query = query;
this.queryMatches = query.matches;
this.matchMediaListener = () => {
this.queryMatches = query.matches;
};
this.query.addEventListener('change', this.matchMediaListener);
}
},
unbindMatchMediaListener() {
if (this.matchMediaListener) {
this.query.removeEventListener('change', this.matchMediaListener);
this.matchMediaListener = null;
}
},
isItemMatched(processedItem) {
return this.isValidItem(processedItem) && this.getProccessedItemLabel(processedItem)?.toLocaleLowerCase().startsWith(this.searchValue.toLocaleLowerCase());
},
Expand Down
47 changes: 45 additions & 2 deletions packages/primevue/src/tieredmenu/style/TieredMenuStyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,60 @@ const theme = ({ dt }) => `
.p-tieredmenu-enter-active {
transition: opacity 250ms;
}
.p-tieredmenu-mobile {
position: relative;
}
.p-tieredmenu-mobile .p-tieredmenu-button {
display: flex;
}
.p-tieredmenu-mobile .p-tieredmenu-root-list > .p-tieredmenu-item > .p-tieredmenu-item-content > .p-tieredmenu-item-link {
padding: ${dt('tieredmenu.item.padding')};
}
.p-tieredmenu-mobile .p-tieredmenu-root-list .p-tieredmenu-separator {
border-top: 1px solid ${dt('tieredmenu.separator.border.color')};
}
.p-tieredmenu-mobile .p-tieredmenu-root-list > .p-tieredmenu-item > .p-tieredmenu-item-content .p-tieredmenu-submenu-icon {
margin-left: auto;
transition: transform 0.2s;
}
.p-tieredmenu-mobile .p-tieredmenu-root-list > .p-tieredmenu-item-active > .p-tieredmenu-item-content .p-tieredmenu-submenu-icon {
transform: rotate(-90deg);
}
.p-tieredmenu-mobile .p-tieredmenu-submenu .p-tieredmenu-submenu-icon {
transition: transform 0.2s;
transform: rotate(90deg);
}
.p-tieredmenu-mobile .p-tieredmenu-item-active > .p-tieredmenu-item-content .p-tieredmenu-submenu-icon {
transform: rotate(-90deg);
}
.p-tieredmenu-mobile .p-tieredmenu-submenu {
position: static;
box-shadow: none;
border: 0 none;
padding-left: ${dt('tieredmenu.submenu.mobile.indent')};
}
`;

const inlineStyles = {
submenu: ({ instance, processedItem }) => ({ display: instance.isItemActive(processedItem) ? 'flex' : 'none' })
};

const classes = {
root: ({ instance, props }) => [
root: ({ props, instance }) => [
'p-tieredmenu p-component',
{
'p-tieredmenu-overlay': props.popup
'p-tieredmenu-overlay': props.popup,
'p-tieredmenu-mobile': instance.queryMatches,
'p-tieredmenu-mobile-active': instance.mobileActive
}
],
start: 'p-tieredmenu-start',
Expand Down
3 changes: 3 additions & 0 deletions packages/themes/src/presets/aura/tieredmenu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export default {
activeColor: '{navigation.item.icon.active.color}'
}
},
submenu: {
mobileIndent: '1rem'
},
submenuLabel: {
padding: '{navigation.submenu.label.padding}',
fontWeight: '{navigation.submenu.label.font.weight}',
Expand Down
3 changes: 3 additions & 0 deletions packages/themes/src/presets/lara/tieredmenu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export default {
activeColor: '{navigation.item.icon.active.color}'
}
},
submenu: {
mobileIndent: '1.25rem'
},
submenuIcon: {
size: '{navigation.submenu.icon.size}',
color: '{navigation.submenu.icon.color}',
Expand Down
3 changes: 3 additions & 0 deletions packages/themes/src/presets/material/tieredmenu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export default {
activeColor: '{navigation.item.icon.active.color}'
}
},
submenu: {
mobileIndent: '1rem'
},
submenuLabel: {
padding: '{navigation.submenu.label.padding}',
fontWeight: '{navigation.submenu.label.font.weight}',
Expand Down
3 changes: 3 additions & 0 deletions packages/themes/src/presets/nora/tieredmenu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export default {
activeColor: '{navigation.item.icon.active.color}'
}
},
submenu: {
mobileIndent: '1rem'
},
submenuLabel: {
padding: '{navigation.submenu.label.padding}',
fontWeight: '{navigation.submenu.label.font.weight}',
Expand Down

0 comments on commit 0c57108

Please sign in to comment.