Refactor #3907 - For Menubar
parent
234ff1062f
commit
2dd290d526
|
@ -10,6 +10,12 @@ const MenubarProps = [
|
|||
type: 'boolean',
|
||||
default: 'true',
|
||||
description: "Whether to apply 'router-link-active-exact' class if route exactly matches the item path."
|
||||
},
|
||||
{
|
||||
name: 'pt',
|
||||
type: 'any',
|
||||
default: 'null',
|
||||
description: 'Uses to pass attributes to DOM elements inside the component.'
|
||||
}
|
||||
];
|
||||
|
||||
|
|
|
@ -11,6 +11,130 @@ import { ButtonHTMLAttributes, VNode } from 'vue';
|
|||
import { MenuItem } from '../menuitem';
|
||||
import { ClassComponent, GlobalComponentConstructor } from '../ts-helpers';
|
||||
|
||||
export declare type MenubarPassThroughOptionType = MenubarPassThroughAttributes | ((options: MenubarPassThroughMethodOptions) => MenubarPassThroughAttributes) | null | undefined;
|
||||
|
||||
/**
|
||||
* Custom passthrough(pt) option method.
|
||||
*/
|
||||
export interface MenubarPassThroughMethodOptions {
|
||||
props: MenubarProps;
|
||||
state: MenubarState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom passthrough(pt) options.
|
||||
* @see {@link MenubarProps.pt}
|
||||
*/
|
||||
export interface MenubarPassThroughOptions {
|
||||
/**
|
||||
* Uses to pass attributes to the root's DOM element.
|
||||
*/
|
||||
root?: MenubarPassThroughOptionType;
|
||||
/**
|
||||
* Uses to pass attributes to the list's DOM element.
|
||||
*/
|
||||
menu?: MenubarPassThroughOptionType;
|
||||
/**
|
||||
* Uses to pass attributes to the list item's DOM element.
|
||||
*/
|
||||
menuitem?: MenubarPassThroughOptionType;
|
||||
/**
|
||||
* Uses to pass attributes to the content's DOM element.
|
||||
*/
|
||||
content?: MenubarPassThroughOptionType;
|
||||
/**
|
||||
* Uses to pass attributes to the action's DOM element.
|
||||
*/
|
||||
action?: MenubarPassThroughOptionType;
|
||||
/**
|
||||
* Uses to pass attributes to the icon's DOM element.
|
||||
*/
|
||||
icon?: MenubarPassThroughOptionType;
|
||||
/**
|
||||
* Uses to pass attributes to the label's DOM element.
|
||||
*/
|
||||
label?: MenubarPassThroughOptionType;
|
||||
/**
|
||||
* Uses to pass attributes to the submenu icon's DOM element.
|
||||
*/
|
||||
submenuicon?: MenubarPassThroughOptionType;
|
||||
/**
|
||||
* Uses to pass attributes to the separator's DOM element.
|
||||
*/
|
||||
separator?: MenubarPassThroughOptionType;
|
||||
/**
|
||||
* Uses to pass attributes to the mobile popup menu button's DOM element.
|
||||
*/
|
||||
button?: MenubarPassThroughOptionType;
|
||||
/**
|
||||
* Uses to pass attributes to the mobile popup menu button icon's DOM element.
|
||||
*/
|
||||
popupIcon?: MenubarPassThroughOptionType;
|
||||
/**
|
||||
* Uses to pass attributes to the start of the component.
|
||||
*/
|
||||
start?: MenubarPassThroughOptionType;
|
||||
/**
|
||||
* Uses to pass attributes to the end of the component.
|
||||
*/
|
||||
end?: MenubarPassThroughOptionType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom passthrough attributes for each DOM elements
|
||||
*/
|
||||
export interface MenubarPassThroughAttributes {
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines focused item info
|
||||
*/
|
||||
export interface MenubarFocusedItemInfo {
|
||||
/**
|
||||
* Active item index
|
||||
*/
|
||||
index: number;
|
||||
/**
|
||||
* Active item level
|
||||
*/
|
||||
level: number;
|
||||
/**
|
||||
* Parent key info
|
||||
*/
|
||||
parentKey: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines current inline state in Menubar component.
|
||||
*/
|
||||
export interface MenubarState {
|
||||
/**
|
||||
* Current id state as a string.
|
||||
*/
|
||||
id: string;
|
||||
/**
|
||||
* Current mobile menu active state as a boolean.
|
||||
* @defaultValue false
|
||||
*/
|
||||
mobileActive: boolean;
|
||||
/**
|
||||
* Current focus state as a boolean.
|
||||
* @defaultValue false
|
||||
*/
|
||||
focused: boolean;
|
||||
/**
|
||||
* Current focused item info.
|
||||
* @type {MenubarFocusedItemInfo}
|
||||
*/
|
||||
focusedItemInfo: MenubarFocusedItemInfo;
|
||||
/**
|
||||
* Active item path.
|
||||
* @type {MenubarFocusedItemInfo}
|
||||
*/
|
||||
activeItemPath: MenubarFocusedItemInfo[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines valid properties in Menubar component.
|
||||
*/
|
||||
|
@ -36,6 +160,11 @@ export interface MenubarProps {
|
|||
* Identifier of the underlying input element.
|
||||
*/
|
||||
'aria-labelledby'?: string | undefined;
|
||||
/**
|
||||
* Uses to pass attributes to DOM elements inside the component.
|
||||
* @type {MenubarPassThroughOptions}
|
||||
*/
|
||||
pt?: MenubarPassThroughOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<template>
|
||||
<div :ref="containerRef" :class="containerClass">
|
||||
<div v-if="$slots.start" class="p-menubar-start">
|
||||
<div :ref="containerRef" :class="containerClass" v-bind="ptm('root')">
|
||||
<div v-if="$slots.start" class="p-menubar-start" v-bind="ptm('start')">
|
||||
<slot name="start"></slot>
|
||||
</div>
|
||||
<a
|
||||
|
@ -15,10 +15,10 @@
|
|||
:aria-label="$primevue.config.locale.aria.navigation"
|
||||
@click="menuButtonClick($event)"
|
||||
@keydown="menuButtonKeydown($event)"
|
||||
v-bind="buttonProps"
|
||||
v-bind="{ ...buttonProps, ...ptm('button') }"
|
||||
>
|
||||
<slot name="popupicon">
|
||||
<BarsIcon />
|
||||
<BarsIcon v-bind="ptm('popupIcon')" />
|
||||
</slot>
|
||||
</a>
|
||||
<MenubarSub
|
||||
|
@ -39,25 +39,28 @@
|
|||
:level="0"
|
||||
:aria-labelledby="ariaLabelledby"
|
||||
:aria-label="ariaLabel"
|
||||
:pt="pt"
|
||||
@focus="onFocus"
|
||||
@blur="onBlur"
|
||||
@keydown="onKeyDown"
|
||||
@item-click="onItemClick"
|
||||
@item-mouseenter="onItemMouseEnter"
|
||||
/>
|
||||
<div v-if="$slots.end" class="p-menubar-end">
|
||||
<div v-if="$slots.end" class="p-menubar-end" v-bind="ptm('end')">
|
||||
<slot name="end"></slot>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import BaseComponent from 'primevue/basecomponent';
|
||||
import BarsIcon from 'primevue/icons/bars';
|
||||
import { DomHandler, ObjectUtils, UniqueComponentId, ZIndexUtils } from 'primevue/utils';
|
||||
import MenubarSub from './MenubarSub.vue';
|
||||
|
||||
export default {
|
||||
name: 'Menubar',
|
||||
extends: BaseComponent,
|
||||
emits: ['focus', 'blur'],
|
||||
props: {
|
||||
model: {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<template>
|
||||
<ul>
|
||||
<ul v-bind="ptm('menu')">
|
||||
<template v-for="(processedItem, index) of items" :key="getItemKey(processedItem)">
|
||||
<li
|
||||
v-if="isItemVisible(processedItem) && !getItemProp(processedItem, 'separator')"
|
||||
|
@ -14,23 +14,24 @@
|
|||
:aria-level="level + 1"
|
||||
:aria-setsize="getAriaSetSize()"
|
||||
:aria-posinset="getAriaPosInset(index)"
|
||||
v-bind="ptm('menuitem')"
|
||||
>
|
||||
<div class="p-menuitem-content" @click="onItemClick($event, processedItem)" @mouseenter="onItemMouseEnter($event, processedItem)">
|
||||
<div class="p-menuitem-content" @click="onItemClick($event, processedItem)" @mouseenter="onItemMouseEnter($event, processedItem)" v-bind="ptm('content')">
|
||||
<template v-if="!templates.item">
|
||||
<router-link v-if="getItemProp(processedItem, 'to') && !isItemDisabled(processedItem)" v-slot="{ navigate, href, isActive, isExactActive }" :to="getItemProp(processedItem, 'to')" custom>
|
||||
<a v-ripple :href="href" :class="getItemActionClass(processedItem, { isActive, isExactActive })" tabindex="-1" aria-hidden="true" @click="onItemActionClick($event, navigate)">
|
||||
<a v-ripple :href="href" :class="getItemActionClass(processedItem, { isActive, isExactActive })" tabindex="-1" aria-hidden="true" @click="onItemActionClick($event, navigate)" v-bind="ptm('action')">
|
||||
<component v-if="templates.itemicon" :is="templates.itemicon" :item="processedItem.item" :class="getItemIconClass(processedItem)" />
|
||||
<span v-else-if="getItemProp(processedItem, 'icon')" :class="getItemIconClass(processedItem)" />
|
||||
<span class="p-menuitem-text">{{ getItemLabel(processedItem) }}</span>
|
||||
<span v-else-if="getItemProp(processedItem, 'icon')" :class="getItemIconClass(processedItem)" v-bind="ptm('icon')" />
|
||||
<span class="p-menuitem-text" v-bind="ptm('label')">{{ getItemLabel(processedItem) }}</span>
|
||||
</a>
|
||||
</router-link>
|
||||
<a v-else v-ripple :href="getItemProp(processedItem, 'url')" :class="getItemActionClass(processedItem)" :target="getItemProp(processedItem, 'target')" tabindex="-1" aria-hidden="true">
|
||||
<a v-else v-ripple :href="getItemProp(processedItem, 'url')" :class="getItemActionClass(processedItem)" :target="getItemProp(processedItem, 'target')" tabindex="-1" aria-hidden="true" v-bind="ptm('action')">
|
||||
<component v-if="templates.itemicon" :is="templates.itemicon" :item="processedItem.item" :class="getItemIconClass(processedItem)" />
|
||||
<span v-else-if="getItemProp(processedItem, 'icon')" :class="getItemIconClass(processedItem)" />
|
||||
<span class="p-menuitem-text">{{ getItemLabel(processedItem) }}</span>
|
||||
<span v-else-if="getItemProp(processedItem, 'icon')" :class="getItemIconClass(processedItem)" v-bind="ptm('icon')" />
|
||||
<span class="p-menuitem-text" v-bind="ptm('label')">{{ getItemLabel(processedItem) }}</span>
|
||||
<template v-if="getItemProp(processedItem, 'items')">
|
||||
<component v-if="templates.submenuicon" :is="templates.submenuicon" :root="root" :active="isItemActive(processedItem)" class="p-submenu-icon" />
|
||||
<component v-else :is="root ? 'AngleDownIcon' : 'AngleRightIcon'" class="p-submenu-icon" />
|
||||
<component v-else :is="root ? 'AngleDownIcon' : 'AngleRightIcon'" class="p-submenu-icon" v-bind="ptm('submenuIcon')" />
|
||||
</template>
|
||||
</a>
|
||||
</template>
|
||||
|
@ -48,16 +49,25 @@
|
|||
:templates="templates"
|
||||
:exact="exact"
|
||||
:level="level + 1"
|
||||
:pt="pt"
|
||||
@item-click="$emit('item-click', $event)"
|
||||
@item-mouseenter="$emit('item-mouseenter', $event)"
|
||||
/>
|
||||
</li>
|
||||
<li v-if="isItemVisible(processedItem) && getItemProp(processedItem, 'separator')" :id="getItemId(processedItem)" :style="getItemProp(processedItem, 'style')" :class="getSeparatorItemClass(processedItem)" role="separator"></li>
|
||||
<li
|
||||
v-if="isItemVisible(processedItem) && getItemProp(processedItem, 'separator')"
|
||||
:id="getItemId(processedItem)"
|
||||
:style="getItemProp(processedItem, 'style')"
|
||||
:class="getSeparatorItemClass(processedItem)"
|
||||
role="separator"
|
||||
v-bind="ptm('separator')"
|
||||
></li>
|
||||
</template>
|
||||
</ul>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import BaseComponent from 'primevue/basecomponent';
|
||||
import AngleDownIcon from 'primevue/icons/angledown';
|
||||
import AngleRightIcon from 'primevue/icons/angleright';
|
||||
import Ripple from 'primevue/ripple';
|
||||
|
@ -65,6 +75,7 @@ import { ObjectUtils } from 'primevue/utils';
|
|||
|
||||
export default {
|
||||
name: 'MenubarSub',
|
||||
extends: BaseComponent,
|
||||
emits: ['item-mouseenter', 'item-click'],
|
||||
props: {
|
||||
items: {
|
||||
|
|
Loading…
Reference in New Issue