refactor: #7090 for MegaMenu

pull/7064/merge
Mert Sincan 2025-01-14 11:11:42 +00:00
parent b05dac3b13
commit cb9867c839
1 changed files with 7 additions and 13 deletions

View File

@ -1,10 +1,10 @@
<template> <template>
<div :ref="containerRef" :id="id" :class="cx('root')" v-bind="ptmi('root')"> <div :ref="containerRef" :id="$id" :class="cx('root')" v-bind="ptmi('root')">
<div v-if="$slots.start" :class="cx('start')" v-bind="ptm('start')"> <div v-if="$slots.start" :class="cx('start')" v-bind="ptm('start')">
<slot name="start"></slot> <slot name="start"></slot>
</div> </div>
<!--TODO: menubutton deprecated since v4.0. Use button--> <!--TODO: menubutton deprecated since v4.0. Use button-->
<slot :id="id" :name="$slots.button ? 'button' : 'menubutton'" :class="cx('button')" :toggleCallback="(event) => menuButtonClick(event)"> <slot :id="$id" :name="$slots.button ? 'button' : 'menubutton'" :class="cx('button')" :toggleCallback="(event) => menuButtonClick(event)">
<a <a
v-if="model && model.length > 0" v-if="model && model.length > 0"
ref="menubutton" ref="menubutton"
@ -13,7 +13,7 @@
:class="cx('button')" :class="cx('button')"
:aria-haspopup="model.length && model.length > 0 ? true : false" :aria-haspopup="model.length && model.length > 0 ? true : false"
:aria-expanded="mobileActive" :aria-expanded="mobileActive"
:aria-controls="id" :aria-controls="$id"
:aria-label="$primevue.config.locale.aria?.navigation" :aria-label="$primevue.config.locale.aria?.navigation"
@click="menuButtonClick($event)" @click="menuButtonClick($event)"
@keydown="menuButtonKeydown($event)" @keydown="menuButtonKeydown($event)"
@ -27,7 +27,7 @@
</slot> </slot>
<MegaMenuSub <MegaMenuSub
:ref="menubarRef" :ref="menubarRef"
:id="id + '_list'" :id="$id + '_list'"
:tabindex="!disabled ? tabindex : -1" :tabindex="!disabled ? tabindex : -1"
role="menubar" role="menubar"
:aria-label="ariaLabel" :aria-label="ariaLabel"
@ -35,7 +35,7 @@
:aria-disabled="disabled || undefined" :aria-disabled="disabled || undefined"
:aria-orientation="orientation" :aria-orientation="orientation"
:aria-activedescendant="focused ? focusedItemId : undefined" :aria-activedescendant="focused ? focusedItemId : undefined"
:menuId="id" :menuId="$id"
:focusedItemId="focused ? focusedItemId : undefined" :focusedItemId="focused ? focusedItemId : undefined"
:items="processedItems" :items="processedItems"
:horizontal="horizontal" :horizontal="horizontal"
@ -62,7 +62,6 @@
import { findSingle, focus, isTouchDevice } from '@primeuix/utils/dom'; import { findSingle, focus, isTouchDevice } from '@primeuix/utils/dom';
import { findLastIndex, isEmpty, isNotEmpty, isPrintableCharacter, resolve } from '@primeuix/utils/object'; import { findLastIndex, isEmpty, isNotEmpty, isPrintableCharacter, resolve } from '@primeuix/utils/object';
import { ZIndex } from '@primeuix/utils/zindex'; import { ZIndex } from '@primeuix/utils/zindex';
import { UniqueComponentId } from '@primevue/core/utils';
import BarsIcon from '@primevue/icons/bars'; import BarsIcon from '@primevue/icons/bars';
import BaseMegaMenu from './BaseMegaMenu.vue'; import BaseMegaMenu from './BaseMegaMenu.vue';
import MegaMenuSub from './MegaMenuSub.vue'; import MegaMenuSub from './MegaMenuSub.vue';
@ -81,7 +80,6 @@ export default {
searchValue: null, searchValue: null,
data() { data() {
return { return {
id: this.$attrs.id,
mobileActive: false, mobileActive: false,
focused: false, focused: false,
focusedItemInfo: { index: -1, key: '', parentKey: '' }, focusedItemInfo: { index: -1, key: '', parentKey: '' },
@ -92,9 +90,6 @@ export default {
}; };
}, },
watch: { watch: {
'$attrs.id': function (newValue) {
this.id = newValue || UniqueComponentId();
},
activeItem(newItem) { activeItem(newItem) {
if (isNotEmpty(newItem)) { if (isNotEmpty(newItem)) {
this.bindOutsideClickListener(); this.bindOutsideClickListener();
@ -106,7 +101,6 @@ export default {
} }
}, },
mounted() { mounted() {
this.id = this.id || UniqueComponentId();
this.bindMatchMediaListener(); this.bindMatchMediaListener();
}, },
beforeUnmount() { beforeUnmount() {
@ -606,7 +600,7 @@ export default {
this.scrollInView(); this.scrollInView();
}, },
scrollInView(index = -1) { scrollInView(index = -1) {
const id = index !== -1 ? `${this.id}_${index}` : this.focusedItemId; const id = index !== -1 ? `${this.$id}_${index}` : this.focusedItemId;
let element; let element;
if (id === null && this.queryMatches) { if (id === null && this.queryMatches) {
@ -675,7 +669,7 @@ export default {
return this.orientation === 'vertical'; return this.orientation === 'vertical';
}, },
focusedItemId() { focusedItemId() {
return isNotEmpty(this.focusedItemInfo.key) ? `${this.id}_${this.focusedItemInfo.key}` : null; return isNotEmpty(this.focusedItemInfo.key) ? `${this.$id}_${this.focusedItemInfo.key}` : null;
} }
}, },
components: { components: {