Implemented TieredMenu
parent
68f72e26c7
commit
5d2d3b13c2
|
@ -2,7 +2,6 @@
|
||||||
@import '../../components/button/Button.css';
|
@import '../../components/button/Button.css';
|
||||||
@import '../../components/checkbox/Checkbox.css';
|
@import '../../components/checkbox/Checkbox.css';
|
||||||
@import '../../components/inputtext/InputText.css';
|
@import '../../components/inputtext/InputText.css';
|
||||||
@import '../../components/menu/Menu.css';
|
|
||||||
@import '../../components/password/Password.css';
|
@import '../../components/password/Password.css';
|
||||||
@import '../../components/radiobutton/RadioButton.css';
|
@import '../../components/radiobutton/RadioButton.css';
|
||||||
@import '../../components/splitbutton/SplitButton.css';
|
@import '../../components/splitbutton/SplitButton.css';
|
|
@ -160,3 +160,48 @@ export default {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.p-menu {
|
||||||
|
width: 12.5em;
|
||||||
|
padding: .25em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.p-menu.p-menu-dynamic {
|
||||||
|
position: absolute;
|
||||||
|
}
|
||||||
|
|
||||||
|
.p-menu .p-menu-separator {
|
||||||
|
border-width: 1px 0 0 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.p-menu ul {
|
||||||
|
list-style: none;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.p-menu .p-submenu-header {
|
||||||
|
padding: .25em .5em;
|
||||||
|
margin: .125em 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.p-menu .p-menuitem {
|
||||||
|
margin: .125em 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.p-menu .p-menuitem-link {
|
||||||
|
padding: .25em;
|
||||||
|
display: block;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.p-menu .p-menuitem-icon {
|
||||||
|
margin-right: .25em;
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
|
|
||||||
|
.p-menu .p-menuitem-text {
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<template>
|
<template>
|
||||||
<transition name="p-input-overlay" @enter="onEnter" @leave="onLeave">
|
<transition name="p-input-overlay" @enter="onEnter" @leave="onLeave">
|
||||||
<div ref="container" :class="containerClass" v-if="popup ? visible : true">
|
<div ref="container" :class="containerClass" v-if="popup ? visible : true">
|
||||||
<TieredMenuSub :model="model" :root="true" />
|
<TieredMenuSub :model="model" :root="true" :popup="popup" />
|
||||||
</div>
|
</div>
|
||||||
</transition>
|
</transition>
|
||||||
</template>
|
</template>
|
||||||
|
@ -159,7 +159,6 @@ export default {
|
||||||
|
|
||||||
.p-tieredmenu.p-tieredmenu-dynamic {
|
.p-tieredmenu.p-tieredmenu-dynamic {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
display: none;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.p-tieredmenu .p-menu-separator {
|
.p-tieredmenu .p-menu-separator {
|
||||||
|
|
|
@ -1,17 +1,21 @@
|
||||||
<template>
|
<template>
|
||||||
<ul ref="element" :class="containerClass" role="menu">
|
<ul ref="element" :class="containerClass" role="menu">
|
||||||
<template v-for="(item, i) of model">
|
<template v-for="(item, i) of model">
|
||||||
<li role="menuitem" :class="getItemClass(item)" :style="item.style" v-if="item.visible !== false && !item.separator" :key="item.label + i">
|
<li role="menuitem" :class="getItemClass(item)" :style="item.style" v-if="item.visible !== false && !item.separator" :key="item.label + i"
|
||||||
<router-link v-if="item.to" :to="item.to" class="p-menuitem-link">
|
@mouseenter="onItemMouseEnter($event, item)">
|
||||||
|
<router-link v-if="item.to" :to="item.to" class="p-menuitem-link"
|
||||||
|
@click.native="onItemClick($event, item)" @keydown.native="onItemKeyDown($event, item)">
|
||||||
<span :class="['p-menuitem-icon', item.icon]"></span>
|
<span :class="['p-menuitem-icon', item.icon]"></span>
|
||||||
<span class="p-menuitem-text">{{item.label}}</span>
|
<span class="p-menuitem-text">{{item.label}}</span>
|
||||||
</router-link>
|
</router-link>
|
||||||
<a v-else :href="item.url||'#'" class="p-menuitem-link" @click="onClick" :target="item.target">
|
<a v-else :href="item.url||'#'" class="p-menuitem-link" :target="item.target"
|
||||||
|
@click="onItemClick($event, item)" @keydown="onItemKeyDown($event, item)">
|
||||||
<span :class="['p-menuitem-icon', item.icon]"></span>
|
<span :class="['p-menuitem-icon', item.icon]"></span>
|
||||||
<span class="p-menuitem-text">{{item.label}}</span>
|
<span class="p-menuitem-text">{{item.label}}</span>
|
||||||
<span class="p-submenu-icon pi pi-fw pi-caret-right" v-if="item.items"></span>
|
<span class="p-submenu-icon pi pi-fw pi-caret-right" v-if="item.items"></span>
|
||||||
</a>
|
</a>
|
||||||
<sub-menu :model="item.items" v-if="item.visible !== false && item.items" :key="item.label + '_sub_'"></sub-menu>
|
<sub-menu :model="item.items" v-if="item.visible !== false && item.items" :key="item.label + '_sub_'"
|
||||||
|
@leaf-click="onLeafClick" @keydown-item="onChildItemKeyDown" :parentActive="item === activeItem" />
|
||||||
</li>
|
</li>
|
||||||
<li class="p-menu-separator" :style="item.style" v-if="item.visible !== false && item.separator" :key="'separator' + i"></li>
|
<li class="p-menu-separator" :style="item.style" v-if="item.visible !== false && item.separator" :key="'separator' + i"></li>
|
||||||
</template>
|
</template>
|
||||||
|
@ -19,6 +23,8 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import DomHandler from '../utils/DomHandler';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'sub-menu',
|
name: 'sub-menu',
|
||||||
props: {
|
props: {
|
||||||
|
@ -39,19 +45,178 @@ export default {
|
||||||
default: false
|
default: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
documentClickListener: null,
|
||||||
|
watch: {
|
||||||
|
parentActive(newValue) {
|
||||||
|
if (!newValue) {
|
||||||
|
this.activeItem = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
activeItem: null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
updated() {
|
||||||
|
if (this.root && this.activeItem) {
|
||||||
|
this.bindDocumentClickListener();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
beforeDestroy() {
|
||||||
|
this.unbindDocumentClickListener();
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
onItemMouseEnter(event, item) {
|
||||||
|
if (item.disabled) {
|
||||||
|
event.preventDefault();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.root) {
|
||||||
|
if (this.activeItem || this.popup) {
|
||||||
|
this.activeItem = item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.activeItem = item;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onItemClick(event, item) {
|
||||||
|
if (item.disabled) {
|
||||||
|
event.preventDefault();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!item.url) {
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (item.command) {
|
||||||
|
item.command({
|
||||||
|
originalEvent: event,
|
||||||
|
item: item
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.root && item.items) {
|
||||||
|
if (this.activeItem && item === this.activeItem)
|
||||||
|
this.activeItem = null;
|
||||||
|
else
|
||||||
|
this.activeItem = item;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!item.items) {
|
||||||
|
this.onLeafClick();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onLeafClick() {
|
||||||
|
this.activeItem = null;
|
||||||
|
|
||||||
|
if (!this.root) {
|
||||||
|
this.$emit('leaf-click');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onItemKeyDown(event, item) {
|
||||||
|
let listItem = event.currentTarget.parentElement;
|
||||||
|
|
||||||
|
switch (event.which) {
|
||||||
|
//down
|
||||||
|
case 40:
|
||||||
|
var nextItem = this.findNextItem(listItem);
|
||||||
|
if (nextItem) {
|
||||||
|
nextItem.children[0].focus();
|
||||||
|
}
|
||||||
|
|
||||||
|
event.preventDefault();
|
||||||
|
break;
|
||||||
|
|
||||||
|
//up
|
||||||
|
case 38:
|
||||||
|
var prevItem = this.findPrevItem(listItem);
|
||||||
|
if (prevItem) {
|
||||||
|
prevItem.children[0].focus();
|
||||||
|
}
|
||||||
|
|
||||||
|
event.preventDefault();
|
||||||
|
break;
|
||||||
|
|
||||||
|
//right
|
||||||
|
case 39:
|
||||||
|
if (item.items) {
|
||||||
|
this.activeItem = item;
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
listItem.children[1].children[0].children[0].focus();
|
||||||
|
}, 50);
|
||||||
|
}
|
||||||
|
|
||||||
|
event.preventDefault();
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.$emit('keydown-item', {
|
||||||
|
originalEvent: event,
|
||||||
|
element: listItem
|
||||||
|
});
|
||||||
|
},
|
||||||
|
onChildItemKeyDown(event) {
|
||||||
|
//left
|
||||||
|
if (event.originalEvent.which === 37) {
|
||||||
|
this.activeItem = null;
|
||||||
|
event.element.parentElement.previousElementSibling.focus();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
findNextItem(item) {
|
||||||
|
let nextItem = item.nextElementSibling;
|
||||||
|
|
||||||
|
if (nextItem)
|
||||||
|
return DomHandler.hasClass(nextItem, 'p-disabled') || !DomHandler.hasClass(nextItem, 'p-menuitem') ? this.findNextItem(nextItem) : nextItem;
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
findPrevItem(item) {
|
||||||
|
let prevItem = item.previousElementSibling;
|
||||||
|
|
||||||
|
if (prevItem)
|
||||||
|
return DomHandler.hasClass(prevItem, 'p-disabled') || !DomHandler.hasClass(prevItem, 'p-menuitem') ? this.findPrevItem(prevItem) : prevItem;
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
},
|
||||||
getItemClass(item) {
|
getItemClass(item) {
|
||||||
return [
|
return [
|
||||||
'p-menuitem', {
|
'p-menuitem', item.class, {
|
||||||
'p-disabled': item.disabled
|
'p-menuitem-active': this.activeItem === item,
|
||||||
|
'p-disabled': item.disabled,
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
bindDocumentClickListener() {
|
||||||
|
if (!this.documentClickListener) {
|
||||||
|
this.documentClickListener = (event) => {
|
||||||
|
if (this.$el && !this.$el.contains(event.target)) {
|
||||||
|
this.activeItem = null;
|
||||||
|
this.unbindDocumentClickListener();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
document.addEventListener('click', this.documentClickListener);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
unbindDocumentClickListener() {
|
||||||
|
if (this.documentClickListener) {
|
||||||
|
document.removeEventListener('click', this.documentClickListener);
|
||||||
|
this.documentClickListener = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
containerClass() {
|
containerClass() {
|
||||||
return {'p-submenu-list': !this.root};
|
return {'p-submenu-list': !this.root};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
|
@ -43,7 +43,7 @@ export default {
|
||||||
label:'Video',
|
label:'Video',
|
||||||
icon:'pi pi-fw pi-video'
|
icon:'pi pi-fw pi-video'
|
||||||
},
|
},
|
||||||
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -79,7 +79,7 @@ export default {
|
||||||
label:'Justify',
|
label:'Justify',
|
||||||
icon:'pi pi-fw pi-align-justify'
|
icon:'pi pi-fw pi-align-justify'
|
||||||
},
|
},
|
||||||
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -89,12 +89,12 @@ export default {
|
||||||
{
|
{
|
||||||
label:'New',
|
label:'New',
|
||||||
icon:'pi pi-fw pi-user-plus',
|
icon:'pi pi-fw pi-user-plus',
|
||||||
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label:'Delete',
|
label:'Delete',
|
||||||
icon:'pi pi-fw pi-user-minus',
|
icon:'pi pi-fw pi-user-minus',
|
||||||
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label:'Search',
|
label:'Search',
|
||||||
|
@ -134,7 +134,7 @@ export default {
|
||||||
label:'Delete',
|
label:'Delete',
|
||||||
icon:'pi pi-fw pi-calendar-minus'
|
icon:'pi pi-fw pi-calendar-minus'
|
||||||
},
|
},
|
||||||
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue