#1275 for Megamenu
parent
23970ebedf
commit
22521d5817
|
@ -10,6 +10,12 @@ const MegaMenuProps = [
|
||||||
type: "string",
|
type: "string",
|
||||||
default: "horizontal",
|
default: "horizontal",
|
||||||
description: "Defines the orientation, valid values are horizontal and vertical."
|
description: "Defines the orientation, valid values are horizontal and vertical."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "exact",
|
||||||
|
type: "boolean",
|
||||||
|
default: "true",
|
||||||
|
description: "Whether to apply 'router-link-active-exact' class if route exactly matches the item path."
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ import { VNode } from 'vue';
|
||||||
interface MegaMenuProps {
|
interface MegaMenuProps {
|
||||||
model?: any[];
|
model?: any[];
|
||||||
orientation?: string;
|
orientation?: string;
|
||||||
|
exact?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
declare class MegaMenu {
|
declare class MegaMenu {
|
||||||
|
|
|
@ -5,13 +5,13 @@
|
||||||
<li v-if="visible(category)" :class="getCategoryClass(category)" :style="category.style"
|
<li v-if="visible(category)" :class="getCategoryClass(category)" :style="category.style"
|
||||||
@mouseenter="onCategoryMouseEnter($event, category)" role="none">
|
@mouseenter="onCategoryMouseEnter($event, category)" role="none">
|
||||||
<template v-if="!$slots.item">
|
<template v-if="!$slots.item">
|
||||||
<router-link v-if="category.to && !disabled(category)" :to="category.to" custom v-slot="{navigate, href}">
|
<router-link v-if="category.to && !disabled(category)" :to="category.to" custom v-slot="{navigate, href, isActive, isExactActive}">
|
||||||
<a :href="href" :class="getLinkClass(category)" @click="onCategoryClick($event, category, navigate)" @keydown="onCategoryKeydown($event, category)" role="menuitem" v-ripple>
|
<a :href="href" :class="linkClass(category, {isActive, isExactActive})" @click="onCategoryClick($event, category, navigate)" @keydown="onCategoryKeydown($event, category)" role="menuitem" v-ripple>
|
||||||
<span v-if="category.icon" :class="getCategoryIcon(category)"></span>
|
<span v-if="category.icon" :class="getCategoryIcon(category)"></span>
|
||||||
<span class="p-menuitem-text">{{category.label}}</span>
|
<span class="p-menuitem-text">{{category.label}}</span>
|
||||||
</a>
|
</a>
|
||||||
</router-link>
|
</router-link>
|
||||||
<a v-else :href="category.url" :class="getLinkClass(category)" :target="category.target" @click="onCategoryClick($event, category)" @keydown="onCategoryKeydown($event, category)"
|
<a v-else :href="category.url" :class="linkClass(category)" :target="category.target" @click="onCategoryClick($event, category)" @keydown="onCategoryKeydown($event, category)"
|
||||||
role="menuitem" :aria-haspopup="category.items != null" :aria-expanded="category === activeItem" :tabindex="disabled(category) ? null : '0'" v-ripple>
|
role="menuitem" :aria-haspopup="category.items != null" :aria-expanded="category === activeItem" :tabindex="disabled(category) ? null : '0'" v-ripple>
|
||||||
<span v-if="category.icon" :class="getCategoryIcon(category)"></span>
|
<span v-if="category.icon" :class="getCategoryIcon(category)"></span>
|
||||||
<span class="p-menuitem-text">{{category.label}}</span>
|
<span class="p-menuitem-text">{{category.label}}</span>
|
||||||
|
@ -27,13 +27,13 @@
|
||||||
<template v-for="(item, i) of submenu.items" :key="item.label + i.toString()">
|
<template v-for="(item, i) of submenu.items" :key="item.label + i.toString()">
|
||||||
<li role="none" :class="getSubmenuItemClass(item)" :style="item.style" v-if="visible(item) && !item.separator">
|
<li role="none" :class="getSubmenuItemClass(item)" :style="item.style" v-if="visible(item) && !item.separator">
|
||||||
<template v-if="!$slots.item">
|
<template v-if="!$slots.item">
|
||||||
<router-link v-if="item.to && !disabled(item)" :to="item.to" custom v-slot="{navigate, href}">
|
<router-link v-if="item.to && !disabled(item)" :to="item.to" custom v-slot="{navigate, href, isActive, isExactActive}">
|
||||||
<a :href="href" :class="getLinkClass(item)" @click="onLeafClick($event, item, navigate)" role="menuitem" v-ripple>
|
<a :href="href" :class="linkClass(item, {isActive, isExactActive})" @click="onLeafClick($event, item, navigate)" role="menuitem" v-ripple>
|
||||||
<span v-if="item.icon" :class="['p-menuitem-icon', item.icon]"></span>
|
<span v-if="item.icon" :class="['p-menuitem-icon', item.icon]"></span>
|
||||||
<span class="p-menuitem-text">{{item.label}}</span>
|
<span class="p-menuitem-text">{{item.label}}</span>
|
||||||
</a>
|
</a>
|
||||||
</router-link>
|
</router-link>
|
||||||
<a v-else :href="item.url" :class="getLinkClass(item)" :target="item.target" @click="onLeafClick($event, item)" role="menuitem" :tabindex="disabled(item) ? null : '0'" v-ripple>
|
<a v-else :href="item.url" :class="linkClass(item)" :target="item.target" @click="onLeafClick($event, item)" role="menuitem" :tabindex="disabled(item) ? null : '0'" v-ripple>
|
||||||
<span v-if="item.icon" :class="['p-menuitem-icon', item.icon]"></span>
|
<span v-if="item.icon" :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="getSubmenuIcon()" v-if="item.items"></span>
|
<span :class="getSubmenuIcon()" v-if="item.items"></span>
|
||||||
|
@ -70,6 +70,10 @@ export default {
|
||||||
orientation: {
|
orientation: {
|
||||||
type: String,
|
type: String,
|
||||||
default: 'horizontal'
|
default: 'horizontal'
|
||||||
|
},
|
||||||
|
exact: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
documentClickListener: null,
|
documentClickListener: null,
|
||||||
|
@ -271,8 +275,12 @@ export default {
|
||||||
getSubmenuItemClass(item) {
|
getSubmenuItemClass(item) {
|
||||||
return ['p-menuitem', item.class];
|
return ['p-menuitem', item.class];
|
||||||
},
|
},
|
||||||
getLinkClass(item) {
|
linkClass(item, routerProps) {
|
||||||
return ['p-menuitem-link', {'p-disabled': this.disabled(item)}];
|
return ['p-menuitem-link', {
|
||||||
|
'p-disabled': this.disabled(item),
|
||||||
|
'router-link-active': routerProps && routerProps.isActive,
|
||||||
|
'router-link-active-exact': this.exact && routerProps && routerProps.isExactActive
|
||||||
|
}];
|
||||||
},
|
},
|
||||||
bindDocumentClickListener() {
|
bindDocumentClickListener() {
|
||||||
if (!this.documentClickListener) {
|
if (!this.documentClickListener) {
|
||||||
|
|
|
@ -155,6 +155,18 @@ export default {
|
||||||
</template>
|
</template>
|
||||||
</MegaMenu>
|
</MegaMenu>
|
||||||
</template>
|
</template>
|
||||||
|
</code></pre>
|
||||||
|
|
||||||
|
<p><i>router-link</i> with route configuration can also be used within templating for further customization.</p>
|
||||||
|
<pre v-code><code><template v-pre>
|
||||||
|
<MegaMenu :model="items">
|
||||||
|
<template #item="{item}">
|
||||||
|
<router-link :to="item.to" custom v-slot="{href, route, navigate, isActive, isExactActive}">
|
||||||
|
<a :href="href" @click="navigate" :class="{'active-link': isActive, 'active-link-exact": isExactActive}>{{route.fullPath}}</a>
|
||||||
|
</router-link>
|
||||||
|
</template>
|
||||||
|
</MegaMenu>
|
||||||
|
</template>
|
||||||
</code></pre>
|
</code></pre>
|
||||||
|
|
||||||
<h5>Properties</h5>
|
<h5>Properties</h5>
|
||||||
|
@ -181,6 +193,12 @@ export default {
|
||||||
<td>string</td>
|
<td>string</td>
|
||||||
<td>horizontal</td>
|
<td>horizontal</td>
|
||||||
<td>Defines the orientation, valid values are horizontal and vertical.</td>
|
<td>Defines the orientation, valid values are horizontal and vertical.</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>exact</td>
|
||||||
|
<td>boolean</td>
|
||||||
|
<td>true</td>
|
||||||
|
<td>Whether to apply 'router-link-active-exact' class if route exactly matches the item path.</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
Loading…
Reference in New Issue