Refactor #3965 - Menu components cx implementation fixes

pull/4004/head
Tuğçe Küçükoğlu 2023-05-29 17:41:08 +03:00
parent ae3dde1f51
commit 8181d7ee85
7 changed files with 30 additions and 29 deletions

View File

@ -56,6 +56,7 @@ const classes = {
menu: 'p-contextmenu-root-list', menu: 'p-contextmenu-root-list',
menuitem: ({ context, processedItem }) => [ menuitem: ({ context, processedItem }) => [
'p-menuitem', 'p-menuitem',
context.getItemProp(processedItem, 'class'),
{ {
'p-menuitem-active p-highlight': context.isItemActive(processedItem), 'p-menuitem-active p-highlight': context.isItemActive(processedItem),
'p-focus': context.isItemFocused(processedItem), 'p-focus': context.isItemFocused(processedItem),
@ -70,11 +71,11 @@ const classes = {
'router-link-active-exact': context.exact && isExactActive 'router-link-active-exact': context.exact && isExactActive
} }
], ],
icon: 'p-menuitem-icon', icon: ({ context, processedItem }) => ['p-menuitem-icon', context.getItemProp(processedItem, 'icon')],
label: 'p-menuitem-text', label: 'p-menuitem-text',
submenuIcon: 'p-submenu-icon', submenuIcon: 'p-submenu-icon',
submenu: 'p-submenu-list', submenu: 'p-submenu-list',
separator: 'p-menuitem-separator' separator: ({ context, processedItem }) => ['p-menuitem-separator', context.getItemProp(processedItem, 'class')]
}; };
const { load: loadStyle, unload: unloadStyle } = useStyle(styles, { id: 'primevue_contextmenu_style', manual: true }); const { load: loadStyle, unload: unloadStyle } = useStyle(styles, { id: 'primevue_contextmenu_style', manual: true });

View File

@ -6,7 +6,7 @@
v-if="isItemVisible(processedItem) && !getItemProp(processedItem, 'separator')" v-if="isItemVisible(processedItem) && !getItemProp(processedItem, 'separator')"
:id="getItemId(processedItem)" :id="getItemId(processedItem)"
:style="getItemProp(processedItem, 'style')" :style="getItemProp(processedItem, 'style')"
:class="[getCXOptions('menuitem', { processedItem }), getItemProp(processedItem, 'class')]" :class="getCXOptions('menuitem', { processedItem })"
role="menuitem" role="menuitem"
:aria-label="getItemLabel(processedItem)" :aria-label="getItemLabel(processedItem)"
:aria-disabled="isItemDisabled(processedItem) || undefined" :aria-disabled="isItemDisabled(processedItem) || undefined"
@ -24,14 +24,14 @@
<template v-if="!templates.item"> <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> <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="getCXOptions('action', { isActive, isExactActive })" tabindex="-1" aria-hidden="true" @click="onItemActionClick($event, navigate)" v-bind="getPTOptions(processedItem, 'action')"> <a v-ripple :href="href" :class="getCXOptions('action', { isActive, isExactActive })" tabindex="-1" aria-hidden="true" @click="onItemActionClick($event, navigate)" v-bind="getPTOptions(processedItem, 'action')">
<component v-if="templates.itemicon" :is="templates.itemicon" :item="processedItem.item" :class="[getCXOptions('icon'), getItemProp(processedItem, 'icon')]" /> <component v-if="templates.itemicon" :is="templates.itemicon" :item="processedItem.item" :class="getCXOptions('icon', { processedItem })" />
<span v-else-if="getItemProp(processedItem, 'icon')" :class="[getCXOptions('icon'), getItemProp(processedItem, 'icon')]" v-bind="getPTOptions(processedItem, 'icon')" /> <span v-else-if="getItemProp(processedItem, 'icon')" :class="getCXOptions('icon', { processedItem })" v-bind="getPTOptions(processedItem, 'icon')" />
<span :class="getCXOptions('label')" v-bind="getPTOptions(processedItem, 'label')">{{ getItemLabel(processedItem) }}</span> <span :class="getCXOptions('label')" v-bind="getPTOptions(processedItem, 'label')">{{ getItemLabel(processedItem) }}</span>
</a> </a>
</router-link> </router-link>
<a v-else v-ripple :href="getItemProp(processedItem, 'url')" :class="getCXOptions('action')" :target="getItemProp(processedItem, 'target')" tabindex="-1" aria-hidden="true" v-bind="getPTOptions(processedItem, 'action')"> <a v-else v-ripple :href="getItemProp(processedItem, 'url')" :class="getCXOptions('action')" :target="getItemProp(processedItem, 'target')" tabindex="-1" aria-hidden="true" v-bind="getPTOptions(processedItem, 'action')">
<component v-if="templates.itemicon" :is="templates.itemicon" :item="processedItem.item" :class="[getCXOptions('icon'), getItemProp(processedItem, 'icon')]" /> <component v-if="templates.itemicon" :is="templates.itemicon" :item="processedItem.item" :class="getCXOptions('icon', { processedItem })" />
<span v-else-if="getItemProp(processedItem, 'icon')" :class="[getCXOptions('icon'), getItemProp(processedItem, 'icon')]" v-bind="getPTOptions(processedItem, 'icon')" /> <span v-else-if="getItemProp(processedItem, 'icon')" :class="getCXOptions('icon', { processedItem })" v-bind="getPTOptions(processedItem, 'icon')" />
<span :class="getCXOptions('label')" v-bind="getPTOptions(processedItem, 'label')">{{ getItemLabel(processedItem) }}</span> <span :class="getCXOptions('label')" v-bind="getPTOptions(processedItem, 'label')">{{ getItemLabel(processedItem) }}</span>
<template v-if="getItemProp(processedItem, 'items')"> <template v-if="getItemProp(processedItem, 'items')">
<component v-if="templates.submenuicon" :is="templates.submenuicon" :active="isItemActive(processedItem)" :class="getCXOptions('submenuIcon')" /> <component v-if="templates.submenuicon" :is="templates.submenuicon" :active="isItemActive(processedItem)" :class="getCXOptions('submenuIcon')" />
@ -64,7 +64,7 @@
v-if="isItemVisible(processedItem) && getItemProp(processedItem, 'separator')" v-if="isItemVisible(processedItem) && getItemProp(processedItem, 'separator')"
:id="getItemId(processedItem)" :id="getItemId(processedItem)"
:style="getItemProp(processedItem, 'style')" :style="getItemProp(processedItem, 'style')"
:class="[getCXOptions('separator'), getItemProp(processedItem, 'class')]" :class="getCXOptions('separator', { processedItem })"
role="separator" role="separator"
v-bind="ptm('separator')" v-bind="ptm('separator')"
></li> ></li>

View File

@ -35,10 +35,11 @@ const classes = {
start: 'p-menu-start', start: 'p-menu-start',
menu: 'p-menu-list p-reset', menu: 'p-menu-list p-reset',
submenuHeader: 'p-submenu-header', submenuHeader: 'p-submenu-header',
separator: 'p-menuitem-separator', separator: ({ item }) => ['p-menuitem-separator', item.class],
end: 'p-menu-end', end: 'p-menu-end',
menuitem: ({ context }) => [ menuitem: ({ context, item }) => [
'p-menuitem', 'p-menuitem',
item.class,
{ {
'p-focus': context.id === context.focusedOptionId, 'p-focus': context.id === context.focusedOptionId,
'p-disabled': context.disabled() 'p-disabled': context.disabled()
@ -52,7 +53,7 @@ const classes = {
'router-link-active-exact': context.exact && isExactActive 'router-link-active-exact': context.exact && isExactActive
} }
], ],
icon: 'p-menuitem-icon', icon: ({ item }) => ['p-menuitem-icon', item.icon],
label: 'p-menuitem-text' label: 'p-menuitem-text'
}; };

View File

@ -26,10 +26,10 @@
</li> </li>
<template v-for="(child, j) of item.items" :key="child.label + i + '_' + j"> <template v-for="(child, j) of item.items" :key="child.label + i + '_' + j">
<PVMenuitem v-if="visible(child) && !child.separator" :id="id + '_' + i + '_' + j" :item="child" :templates="$slots" :exact="exact" :focusedOptionId="focusedOptionId" @item-click="itemClick" :pt="pt" /> <PVMenuitem v-if="visible(child) && !child.separator" :id="id + '_' + i + '_' + j" :item="child" :templates="$slots" :exact="exact" :focusedOptionId="focusedOptionId" @item-click="itemClick" :pt="pt" />
<li v-else-if="visible(child) && child.separator" :key="'separator' + i + j" :class="[cx('separator'), item.class]" :style="child.style" role="separator" v-bind="ptm('separator')"></li> <li v-else-if="visible(child) && child.separator" :key="'separator' + i + j" :class="cx('separator', { item })" :style="child.style" role="separator" v-bind="ptm('separator')"></li>
</template> </template>
</template> </template>
<li v-else-if="visible(item) && item.separator" :key="'separator' + i.toString()" :class="[cx('separator'), item.class]" :style="item.style" role="separator" v-bind="ptm('separator')"></li> <li v-else-if="visible(item) && item.separator" :key="'separator' + i.toString()" :class="cx('separator', { item })" :style="item.style" role="separator" v-bind="ptm('separator')"></li>
<PVMenuitem v-else :key="label(item) + i.toString()" :id="id + '_' + i" :item="item" :templates="$slots" :exact="exact" :focusedOptionId="focusedOptionId" @item-click="itemClick" :pt="pt" /> <PVMenuitem v-else :key="label(item) + i.toString()" :id="id + '_' + i" :item="item" :templates="$slots" :exact="exact" :focusedOptionId="focusedOptionId" @item-click="itemClick" :pt="pt" />
</template> </template>
</ul> </ul>

View File

@ -2,7 +2,7 @@
<li <li
v-if="visible()" v-if="visible()"
:id="id" :id="id"
:class="[getCXOptions('menuitem'), item.class]" :class="getCXOptions('menuitem', { item })"
role="menuitem" role="menuitem"
:style="item.style" :style="item.style"
:aria-label="label()" :aria-label="label()"
@ -15,14 +15,14 @@
<template v-if="!templates.item"> <template v-if="!templates.item">
<router-link v-if="item.to && !disabled()" v-slot="{ navigate, href, isActive, isExactActive }" :to="item.to" custom> <router-link v-if="item.to && !disabled()" v-slot="{ navigate, href, isActive, isExactActive }" :to="item.to" custom>
<a v-ripple :href="href" :class="getCXOptions('action', { isActive, isExactActive })" tabindex="-1" aria-hidden="true" @click="onItemActionClick($event, navigate)" v-bind="getPTOptions('action')"> <a v-ripple :href="href" :class="getCXOptions('action', { isActive, isExactActive })" tabindex="-1" aria-hidden="true" @click="onItemActionClick($event, navigate)" v-bind="getPTOptions('action')">
<component v-if="templates.itemicon" :is="templates.itemicon" :item="item" :class="[getCXOptions('icon'), item.icon]" /> <component v-if="templates.itemicon" :is="templates.itemicon" :item="item" :class="getCXOptions('icon', { item })" />
<span v-else-if="item.icon" :class="[getCXOptions('icon'), item.icon]" v-bind="getPTOptions('icon')" /> <span v-else-if="item.icon" :class="getCXOptions('icon', { item })" v-bind="getPTOptions('icon')" />
<span :class="getCXOptions('label')" v-bind="getPTOptions('label')">{{ label() }}</span> <span :class="getCXOptions('label')" v-bind="getPTOptions('label')">{{ label() }}</span>
</a> </a>
</router-link> </router-link>
<a v-else v-ripple :href="item.url" :class="getCXOptions('action')" :target="item.target" tabindex="-1" aria-hidden="true" v-bind="getPTOptions('action')"> <a v-else v-ripple :href="item.url" :class="getCXOptions('action')" :target="item.target" tabindex="-1" aria-hidden="true" v-bind="getPTOptions('action')">
<component v-if="templates.itemicon" :is="templates.itemicon" :item="item" :class="[getCXOptions('icon'), item.icon]" /> <component v-if="templates.itemicon" :is="templates.itemicon" :item="item" :class="getCXOptions('icon', { item })" />
<span v-else-if="item.icon" :class="[getCXOptions('icon'), item.icon]" v-bind="getPTOptions('icon')" /> <span v-else-if="item.icon" :class="getCXOptions('icon', { item })" v-bind="getPTOptions('icon')" />
<span :class="getCXOptions('label')" v-bind="getPTOptions('label')">{{ label() }}</span> <span :class="getCXOptions('label')" v-bind="getPTOptions('label')">{{ label() }}</span>
</a> </a>
</template> </template>

View File

@ -60,6 +60,7 @@ const classes = {
menu: 'p-tieredmenu-root-list', menu: 'p-tieredmenu-root-list',
menuitem: ({ context, processedItem }) => [ menuitem: ({ context, processedItem }) => [
'p-menuitem', 'p-menuitem',
context.getItemProp(processedItem, 'class'),
{ {
'p-menuitem-active p-highlight': context.isItemActive(processedItem), 'p-menuitem-active p-highlight': context.isItemActive(processedItem),
'p-focus': context.isItemFocused(processedItem), 'p-focus': context.isItemFocused(processedItem),
@ -74,10 +75,11 @@ const classes = {
'router-link-active-exact': context.exact && isExactActive 'router-link-active-exact': context.exact && isExactActive
} }
], ],
icon: 'p-menuitem-icon', icon: ({ context, processedItem }) => ['p-menuitem-icon', context.getItemProp(processedItem, 'icon')],
text: 'p-menuitem-text', text: 'p-menuitem-text',
submenuIcon: 'p-submenu-icon', submenuIcon: 'p-submenu-icon',
submenu: 'p-submenu-list' submenu: 'p-submenu-list',
separator: ({ context, processedItem }) => ['p-menuitem-separator', context.getItemProp(processedItem, 'class')]
}; };
const { load: loadStyle, unload: unloadStyle } = useStyle(styles, { id: 'primevue_tieredmenu_style', manual: true }); const { load: loadStyle, unload: unloadStyle } = useStyle(styles, { id: 'primevue_tieredmenu_style', manual: true });

View File

@ -5,7 +5,7 @@
v-if="isItemVisible(processedItem) && !getItemProp(processedItem, 'separator')" v-if="isItemVisible(processedItem) && !getItemProp(processedItem, 'separator')"
:id="getItemId(processedItem)" :id="getItemId(processedItem)"
:style="getItemProp(processedItem, 'style')" :style="getItemProp(processedItem, 'style')"
:class="[getCXOptions('menuitem', { processedItem }), getItemProp(processedItem, 'class')]" :class="getCXOptions('menuitem', { processedItem })"
role="menuitem" role="menuitem"
:aria-label="getItemLabel(processedItem)" :aria-label="getItemLabel(processedItem)"
:aria-disabled="isItemDisabled(processedItem) || undefined" :aria-disabled="isItemDisabled(processedItem) || undefined"
@ -23,14 +23,14 @@
<template v-if="!templates.item"> <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> <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="getCXOptions('action', { isActive, isExactActive })" tabindex="-1" aria-hidden="true" @click="onItemActionClick($event, navigate)" v-bind="getPTOptions(processedItem, 'action')"> <a v-ripple :href="href" :class="getCXOptions('action', { isActive, isExactActive })" tabindex="-1" aria-hidden="true" @click="onItemActionClick($event, navigate)" v-bind="getPTOptions(processedItem, 'action')">
<component v-if="templates.itemicon" :is="templates.itemicon" :item="processedItem.item" :class="[getCXOptions('icon'), getItemProp(processedItem, 'icon')]" /> <component v-if="templates.itemicon" :is="templates.itemicon" :item="processedItem.item" :class="getCXOptions('icon', { processedItem })" />
<span v-else-if="getItemProp(processedItem, 'icon')" :class="[getCXOptions('icon'), getItemProp(processedItem, 'icon')]" v-bind="getPTOptions(processedItem, 'icon')" /> <span v-else-if="getItemProp(processedItem, 'icon')" :class="getCXOptions('icon', { processedItem })" v-bind="getPTOptions(processedItem, 'icon')" />
<span :class="getCXOptions('label')" v-bind="getPTOptions(processedItem, 'label')">{{ getItemLabel(processedItem) }}</span> <span :class="getCXOptions('label')" v-bind="getPTOptions(processedItem, 'label')">{{ getItemLabel(processedItem) }}</span>
</a> </a>
</router-link> </router-link>
<a v-else v-ripple :href="getItemProp(processedItem, 'url')" :class="getCXOptions('action')" :target="getItemProp(processedItem, 'target')" tabindex="-1" aria-hidden="true" v-bind="getPTOptions(processedItem, 'action')"> <a v-else v-ripple :href="getItemProp(processedItem, 'url')" :class="getCXOptions('action')" :target="getItemProp(processedItem, 'target')" tabindex="-1" aria-hidden="true" v-bind="getPTOptions(processedItem, 'action')">
<component v-if="templates.itemicon" :is="templates.itemicon" :item="processedItem.item" :class="[getCXOptions('icon'), getItemProp(processedItem, 'icon')]" /> <component v-if="templates.itemicon" :is="templates.itemicon" :item="processedItem.item" :class="getCXOptions('icon', { processedItem })" />
<span v-else-if="getItemProp(processedItem, 'icon')" :class="[getCXOptions('icon'), getItemProp(processedItem, 'icon')]" v-bind="getPTOptions(processedItem, 'icon')" /> <span v-else-if="getItemProp(processedItem, 'icon')" :class="getCXOptions('icon', { processedItem })" v-bind="getPTOptions(processedItem, 'icon')" />
<span :class="getCXOptions('label')" v-bind="getPTOptions(processedItem, 'label')">{{ getItemLabel(processedItem) }}</span> <span :class="getCXOptions('label')" v-bind="getPTOptions(processedItem, 'label')">{{ getItemLabel(processedItem) }}</span>
<template v-if="getItemProp(processedItem, 'items')"> <template v-if="getItemProp(processedItem, 'items')">
<component v-if="templates.submenuicon" :is="templates.submenuicon" :class="getCXOptions('submenuIcon')" :active="isItemActive(processedItem)" v-bind="getPTOptions(processedItem, 'submenuIcon')" /> <component v-if="templates.submenuicon" :is="templates.submenuicon" :class="getCXOptions('submenuIcon')" :active="isItemActive(processedItem)" v-bind="getPTOptions(processedItem, 'submenuIcon')" />
@ -61,7 +61,7 @@
v-if="isItemVisible(processedItem) && getItemProp(processedItem, 'separator')" v-if="isItemVisible(processedItem) && getItemProp(processedItem, 'separator')"
:id="getItemId(processedItem)" :id="getItemId(processedItem)"
:style="getItemProp(processedItem, 'style')" :style="getItemProp(processedItem, 'style')"
:class="getSeparatorItemClass(processedItem)" :class="getCXOptions('separator', { processedItem })"
role="separator" role="separator"
v-bind="ptm('separator')" v-bind="ptm('separator')"
></li> ></li>
@ -176,9 +176,6 @@ export default {
}, },
getAriaPosInset(index) { getAriaPosInset(index) {
return index - this.items.slice(0, index).filter((processedItem) => this.isItemVisible(processedItem) && this.getItemProp(processedItem, 'separator')).length + 1; return index - this.items.slice(0, index).filter((processedItem) => this.isItemVisible(processedItem) && this.getItemProp(processedItem, 'separator')).length + 1;
},
getSeparatorItemClass(processedItem) {
return ['p-menuitem-separator', this.getItemProp(processedItem, 'class')];
} }
}, },
components: { components: {