refactor: #7090 for Menubar
parent
432e1c7e87
commit
180fdb88e9
|
@ -3,7 +3,7 @@
|
||||||
<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>
|
||||||
<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)">
|
||||||
<!-- TODO: menubutton deprecated since v4.0-->
|
<!-- TODO: menubutton deprecated since v4.0-->
|
||||||
<a
|
<a
|
||||||
v-if="model && model.length > 0"
|
v-if="model && model.length > 0"
|
||||||
|
@ -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>
|
||||||
<MenubarSub
|
<MenubarSub
|
||||||
:ref="menubarRef"
|
:ref="menubarRef"
|
||||||
:id="id + '_list'"
|
:id="$id + '_list'"
|
||||||
role="menubar"
|
role="menubar"
|
||||||
:items="processedItems"
|
:items="processedItems"
|
||||||
:templates="$slots"
|
:templates="$slots"
|
||||||
|
@ -35,7 +35,7 @@
|
||||||
:mobileActive="mobileActive"
|
:mobileActive="mobileActive"
|
||||||
tabindex="0"
|
tabindex="0"
|
||||||
:aria-activedescendant="focused ? focusedItemId : undefined"
|
:aria-activedescendant="focused ? focusedItemId : undefined"
|
||||||
:menuId="id"
|
:menuId="$id"
|
||||||
:focusedItemId="focused ? focusedItemId : undefined"
|
:focusedItemId="focused ? focusedItemId : undefined"
|
||||||
:activeItemPath="activeItemPath"
|
:activeItemPath="activeItemPath"
|
||||||
:level="0"
|
:level="0"
|
||||||
|
@ -57,9 +57,8 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { UniqueComponentId } from '@primevue/core/utils';
|
import { findSingle, focus, isTouchDevice } from '@primeuix/utils/dom';
|
||||||
import { focus, isTouchDevice, findSingle } from '@primeuix/utils/dom';
|
import { findLastIndex, isEmpty, isNotEmpty, isPrintableCharacter, resolve } from '@primeuix/utils/object';
|
||||||
import { isNotEmpty, resolve, isPrintableCharacter, isEmpty, findLastIndex } from '@primeuix/utils/object';
|
|
||||||
import { ZIndex } from '@primeuix/utils/zindex';
|
import { ZIndex } from '@primeuix/utils/zindex';
|
||||||
import BarsIcon from '@primevue/icons/bars';
|
import BarsIcon from '@primevue/icons/bars';
|
||||||
import BaseMenubar from './BaseMenubar.vue';
|
import BaseMenubar from './BaseMenubar.vue';
|
||||||
|
@ -73,7 +72,6 @@ export default {
|
||||||
matchMediaListener: null,
|
matchMediaListener: null,
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
id: this.$attrs.id,
|
|
||||||
mobileActive: false,
|
mobileActive: false,
|
||||||
focused: false,
|
focused: false,
|
||||||
focusedItemInfo: { index: -1, level: 0, parentKey: '' },
|
focusedItemInfo: { index: -1, level: 0, parentKey: '' },
|
||||||
|
@ -84,9 +82,6 @@ export default {
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
'$attrs.id': function (newValue) {
|
|
||||||
this.id = newValue || UniqueComponentId();
|
|
||||||
},
|
|
||||||
activeItemPath(newPath) {
|
activeItemPath(newPath) {
|
||||||
if (isNotEmpty(newPath)) {
|
if (isNotEmpty(newPath)) {
|
||||||
this.bindOutsideClickListener();
|
this.bindOutsideClickListener();
|
||||||
|
@ -101,7 +96,6 @@ export default {
|
||||||
container: null,
|
container: null,
|
||||||
menubar: null,
|
menubar: null,
|
||||||
mounted() {
|
mounted() {
|
||||||
this.id = this.id || UniqueComponentId();
|
|
||||||
this.bindMatchMediaListener();
|
this.bindMatchMediaListener();
|
||||||
},
|
},
|
||||||
beforeUnmount() {
|
beforeUnmount() {
|
||||||
|
@ -590,7 +584,7 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
scrollInView(index = -1) {
|
scrollInView(index = -1) {
|
||||||
const id = index !== -1 ? `${this.id}_${index}` : this.focusedItemId;
|
const id = index !== -1 ? `${this.$id}_${index}` : this.focusedItemId;
|
||||||
const element = findSingle(this.menubar, `li[id="${id}"]`);
|
const element = findSingle(this.menubar, `li[id="${id}"]`);
|
||||||
|
|
||||||
if (element) {
|
if (element) {
|
||||||
|
@ -635,7 +629,7 @@ export default {
|
||||||
return processedItem ? processedItem.items : this.processedItems;
|
return processedItem ? processedItem.items : this.processedItems;
|
||||||
},
|
},
|
||||||
focusedItemId() {
|
focusedItemId() {
|
||||||
return this.focusedItemInfo.index !== -1 ? `${this.id}${isNotEmpty(this.focusedItemInfo.parentKey) ? '_' + this.focusedItemInfo.parentKey : ''}_${this.focusedItemInfo.index}` : null;
|
return this.focusedItemInfo.index !== -1 ? `${this.$id}${isNotEmpty(this.focusedItemInfo.parentKey) ? '_' + this.focusedItemInfo.parentKey : ''}_${this.focusedItemInfo.index}` : null;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
components: {
|
components: {
|
||||||
|
|
Loading…
Reference in New Issue