Refactor #4351 - For PanelMenu

pull/4356/head
Tuğçe Küçükoğlu 2023-08-30 10:27:49 +03:00
parent 6ec518c771
commit d8b1f2c944
3 changed files with 40 additions and 1 deletions

View File

@ -50,6 +50,7 @@
@header-focus="updateFocusedHeader" @header-focus="updateFocusedHeader"
:exact="exact" :exact="exact"
:pt="pt" :pt="pt"
:unstyled="unstyled"
/> />
</div> </div>
</div> </div>
@ -81,6 +82,11 @@ export default {
this.id = newValue || UniqueComponentId(); this.id = newValue || UniqueComponentId();
} }
}, },
beforeMount() {
if (!this.$slots.item) {
console.warn('In future versions, vue-router support will be removed. Item templating should be used.');
}
},
mounted() { mounted() {
this.id = this.id || UniqueComponentId(); this.id = this.id || UniqueComponentId();
}, },

View File

@ -16,6 +16,7 @@
@keydown="onKeyDown" @keydown="onKeyDown"
@item-toggle="onItemToggle" @item-toggle="onItemToggle"
:pt="pt" :pt="pt"
:unstyled="unstyled"
v-bind="ptm('menu')" v-bind="ptm('menu')"
/> />
</template> </template>

View File

@ -35,7 +35,7 @@
<span :class="cx('label')" v-bind="getPTOptions('label', processedItem, index)">{{ getItemLabel(processedItem) }}</span> <span :class="cx('label')" v-bind="getPTOptions('label', processedItem, index)">{{ getItemLabel(processedItem) }}</span>
</a> </a>
</template> </template>
<component v-else :is="templates.item" :item="processedItem.item"></component> <component v-else :is="templates.item" :item="processedItem.item" :label="getItemLabel(processedItem)" :props="getMenuItemProps(processedItem, index)"></component>
</div> </div>
<transition name="p-toggleable-content" v-bind="ptm('transition')"> <transition name="p-toggleable-content" v-bind="ptm('transition')">
<div v-show="isItemActive(processedItem)" :class="cx('toggleableContent')" v-bind="ptm('toggleableContent')"> <div v-show="isItemActive(processedItem)" :class="cx('toggleableContent')" v-bind="ptm('toggleableContent')">
@ -52,6 +52,7 @@
:exact="exact" :exact="exact"
@item-toggle="onItemToggle" @item-toggle="onItemToggle"
:pt="pt" :pt="pt"
:unstyled="unstyled"
v-bind="ptm('submenu')" v-bind="ptm('submenu')"
/> />
</div> </div>
@ -74,6 +75,7 @@ import ChevronDownIcon from 'primevue/icons/chevrondown';
import ChevronRightIcon from 'primevue/icons/chevronright'; import ChevronRightIcon from 'primevue/icons/chevronright';
import Ripple from 'primevue/ripple'; import Ripple from 'primevue/ripple';
import { ObjectUtils } from 'primevue/utils'; import { ObjectUtils } from 'primevue/utils';
import { mergeProps } from 'vue';
export default { export default {
name: 'PanelMenuSub', name: 'PanelMenuSub',
@ -167,6 +169,36 @@ 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;
},
getMenuItemProps(processedItem, index) {
return {
action: mergeProps(
{
class: this.cx('action'),
tabindex: -1,
'aria-hidden': true
},
this.getPTOptions('action', processedItem, index)
),
icon: mergeProps(
{
class: [this.cx('icon'), this.getItemProp(processedItem, 'icon')]
},
this.getPTOptions('icon', processedItem, index)
),
label: mergeProps(
{
class: this.cx('label')
},
this.getPTOptions('label', processedItem, index)
),
submenuicon: mergeProps(
{
class: this.cx('submenuIcon')
},
this.getPTOptions('submenuicon', processedItem, index)
)
};
} }
}, },
components: { components: {