Refactor #6522 - For ContextMenu
parent
bd47bd35fd
commit
ee1b6260d7
|
@ -26,6 +26,10 @@ export default {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false
|
default: false
|
||||||
},
|
},
|
||||||
|
breakpoint: {
|
||||||
|
type: String,
|
||||||
|
default: '960px'
|
||||||
|
},
|
||||||
tabindex: {
|
tabindex: {
|
||||||
type: Number,
|
type: Number,
|
||||||
default: 0
|
default: 0
|
||||||
|
|
|
@ -227,6 +227,16 @@ export interface ContextMenuProps {
|
||||||
* An array of menuitems.
|
* An array of menuitems.
|
||||||
*/
|
*/
|
||||||
model?: MenuItem[] | undefined;
|
model?: MenuItem[] | undefined;
|
||||||
|
/**
|
||||||
|
* The breakpoint to define the maximum width boundary.
|
||||||
|
* @defaultValue 960px
|
||||||
|
*/
|
||||||
|
breakpoint?: string | undefined;
|
||||||
|
/**
|
||||||
|
* Attaches the menu to document instead of a particular item.
|
||||||
|
* @defaultValue false
|
||||||
|
*/
|
||||||
|
global?: boolean | undefined;
|
||||||
/**
|
/**
|
||||||
* A valid query selector or an HTMLElement to specify where the overlay gets attached.
|
* A valid query selector or an HTMLElement to specify where the overlay gets attached.
|
||||||
* @defaultValue body
|
* @defaultValue body
|
||||||
|
@ -242,11 +252,6 @@ export interface ContextMenuProps {
|
||||||
* @defaultValue 0
|
* @defaultValue 0
|
||||||
*/
|
*/
|
||||||
baseZIndex?: number | undefined;
|
baseZIndex?: number | undefined;
|
||||||
/**
|
|
||||||
* Attaches the menu to document instead of a particular item.
|
|
||||||
* @defaultValue false
|
|
||||||
*/
|
|
||||||
global?: boolean | undefined;
|
|
||||||
/**
|
/**
|
||||||
* Index of the element in tabbing order.
|
* Index of the element in tabbing order.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -52,6 +52,7 @@ export default {
|
||||||
outsideClickListener: null,
|
outsideClickListener: null,
|
||||||
resizeListener: null,
|
resizeListener: null,
|
||||||
documentContextMenuListener: null,
|
documentContextMenuListener: null,
|
||||||
|
matchMediaListener: null,
|
||||||
pageX: null,
|
pageX: null,
|
||||||
pageY: null,
|
pageY: null,
|
||||||
container: null,
|
container: null,
|
||||||
|
@ -63,7 +64,9 @@ export default {
|
||||||
focusedItemInfo: { index: -1, level: 0, parentKey: '' },
|
focusedItemInfo: { index: -1, level: 0, parentKey: '' },
|
||||||
activeItemPath: [],
|
activeItemPath: [],
|
||||||
visible: false,
|
visible: false,
|
||||||
submenuVisible: false
|
submenuVisible: false,
|
||||||
|
query: null,
|
||||||
|
queryMatches: false
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
|
@ -82,6 +85,7 @@ export default {
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.id = this.id || UniqueComponentId();
|
this.id = this.id || UniqueComponentId();
|
||||||
|
this.bindMatchMediaListener();
|
||||||
|
|
||||||
if (this.global) {
|
if (this.global) {
|
||||||
this.bindDocumentContextMenuListener();
|
this.bindDocumentContextMenuListener();
|
||||||
|
@ -91,6 +95,7 @@ export default {
|
||||||
this.unbindResizeListener();
|
this.unbindResizeListener();
|
||||||
this.unbindOutsideClickListener();
|
this.unbindOutsideClickListener();
|
||||||
this.unbindDocumentContextMenuListener();
|
this.unbindDocumentContextMenuListener();
|
||||||
|
this.unbindMatchMediaListener();
|
||||||
|
|
||||||
if (this.container && this.autoZIndex) {
|
if (this.container && this.autoZIndex) {
|
||||||
ZIndex.clear(this.container);
|
ZIndex.clear(this.container);
|
||||||
|
@ -465,6 +470,26 @@ export default {
|
||||||
this.documentContextMenuListener = null;
|
this.documentContextMenuListener = 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) {
|
isItemMatched(processedItem) {
|
||||||
return this.isValidItem(processedItem) && this.getProccessedItemLabel(processedItem)?.toLocaleLowerCase().startsWith(this.searchValue.toLocaleLowerCase());
|
return this.isValidItem(processedItem) && this.getProccessedItemLabel(processedItem)?.toLocaleLowerCase().startsWith(this.searchValue.toLocaleLowerCase());
|
||||||
},
|
},
|
||||||
|
|
|
@ -124,10 +124,56 @@ const theme = ({ dt }) => `
|
||||||
.p-contextmenu-enter-active {
|
.p-contextmenu-enter-active {
|
||||||
transition: opacity 250ms;
|
transition: opacity 250ms;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.p-contextmenu-mobile {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.p-contextmenu-mobile .p-contextmenu-button {
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
|
||||||
|
.p-contextmenu-mobile .p-contextmenu-root-list .p-contextmenu-item {
|
||||||
|
position: static;
|
||||||
|
}
|
||||||
|
|
||||||
|
.p-contextmenu-mobile .p-contextmenu-root-list .p-contextmenu-separator {
|
||||||
|
border-top: 1px solid ${dt('contextmenu.separator.border.color')};
|
||||||
|
}
|
||||||
|
|
||||||
|
.p-contextmenu-mobile .p-contextmenu-root-list > .p-contextmenu-item > .p-contextmenu-item-content .p-contextmenu-submenu-icon {
|
||||||
|
margin-left: auto;
|
||||||
|
transition: transform 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.p-contextmenu-mobile .p-contextmenu-root-list > .p-contextmenu-item-active > .p-contextmenu-item-content .p-contextmenu-submenu-icon {
|
||||||
|
transform: rotate(-90deg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.p-contextmenu-mobile .p-contextmenu-submenu .p-contextmenu-submenu-icon {
|
||||||
|
transition: transform 0.2s;
|
||||||
|
transform: rotate(90deg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.p-contextmenu-mobile .p-contextmenu-item-active > .p-contextmenu-item-content .p-contextmenu-submenu-icon {
|
||||||
|
transform: rotate(-90deg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.p-contextmenu-mobile .p-contextmenu-submenu {
|
||||||
|
position: static;
|
||||||
|
box-shadow: none;
|
||||||
|
border: 0 none;
|
||||||
|
padding-left: ${dt('contextmenu.submenu.mobile.indent')};
|
||||||
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const classes = {
|
const classes = {
|
||||||
root: 'p-contextmenu p-component',
|
root: ({ instance }) => [
|
||||||
|
'p-contextmenu p-component',
|
||||||
|
{
|
||||||
|
'p-contextmenu-mobile': instance.queryMatches
|
||||||
|
}
|
||||||
|
],
|
||||||
rootList: 'p-contextmenu-root-list',
|
rootList: 'p-contextmenu-root-list',
|
||||||
item: ({ instance, processedItem }) => [
|
item: ({ instance, processedItem }) => [
|
||||||
'p-contextmenu-item',
|
'p-contextmenu-item',
|
||||||
|
|
|
@ -26,6 +26,9 @@ export default {
|
||||||
activeColor: '{navigation.item.icon.active.color}'
|
activeColor: '{navigation.item.icon.active.color}'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
submenu: {
|
||||||
|
mobileIndent: '1rem'
|
||||||
|
},
|
||||||
submenuIcon: {
|
submenuIcon: {
|
||||||
size: '{navigation.submenu.icon.size}',
|
size: '{navigation.submenu.icon.size}',
|
||||||
color: '{navigation.submenu.icon.color}',
|
color: '{navigation.submenu.icon.color}',
|
||||||
|
|
|
@ -26,6 +26,9 @@ export default {
|
||||||
activeColor: '{navigation.item.icon.active.color}'
|
activeColor: '{navigation.item.icon.active.color}'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
submenu: {
|
||||||
|
mobileIndent: '1.25rem'
|
||||||
|
},
|
||||||
submenuLabel: {
|
submenuLabel: {
|
||||||
padding: '{navigation.submenu.label.padding}',
|
padding: '{navigation.submenu.label.padding}',
|
||||||
fontWeight: '{navigation.submenu.label.font.weight}',
|
fontWeight: '{navigation.submenu.label.font.weight}',
|
||||||
|
|
|
@ -26,6 +26,9 @@ export default {
|
||||||
activeColor: '{navigation.item.icon.active.color}'
|
activeColor: '{navigation.item.icon.active.color}'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
submenu: {
|
||||||
|
mobileIndent: '1rem'
|
||||||
|
},
|
||||||
submenuIcon: {
|
submenuIcon: {
|
||||||
size: '{navigation.submenu.icon.size}',
|
size: '{navigation.submenu.icon.size}',
|
||||||
color: '{navigation.submenu.icon.color}',
|
color: '{navigation.submenu.icon.color}',
|
||||||
|
|
|
@ -26,6 +26,9 @@ export default {
|
||||||
activeColor: '{navigation.item.icon.active.color}'
|
activeColor: '{navigation.item.icon.active.color}'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
submenu: {
|
||||||
|
mobileIndent: '1rem'
|
||||||
|
},
|
||||||
submenuIcon: {
|
submenuIcon: {
|
||||||
size: '{navigation.submenu.icon.size}',
|
size: '{navigation.submenu.icon.size}',
|
||||||
color: '{navigation.submenu.icon.color}',
|
color: '{navigation.submenu.icon.color}',
|
||||||
|
|
Loading…
Reference in New Issue