Fixed #4862 - MegaMenu / Menubar: menubutton templating

pull/4864/head
tugcekucukoglu 2023-11-22 13:36:31 +03:00
parent dd2f455683
commit 7d86b48f28
4 changed files with 93 additions and 42 deletions

View File

@ -318,6 +318,29 @@ export interface MegaMenuSlots {
*/ */
hasSubmenu: boolean; hasSubmenu: boolean;
}): VNode[]; }): VNode[];
/**
* Custom menu button template on responsive mode.
* @param {Object} scope - menu button slot's params.
*/
menubutton(scope: {
/**
* Current id state as a string
*/
id: string;
/**
* Style class of component
*/
class: string;
/**
*
* Toggle event
*/
toggleCallback: () => void;
}): VNode[];
/**
* Custom menu button icon template on responsive mode.
*/
menubuttonicon(): VNode[];
/** /**
* Custom submenu icon template. * Custom submenu icon template.
* @param {Object} scope - submenuicon slot's params. * @param {Object} scope - submenuicon slot's params.

View File

@ -3,6 +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="menubutton" :class="cx('menubutton')" :toggleCallback="(event) => menuButtonClick(event)">
<a <a
v-if="model && model.length > 0" v-if="model && model.length > 0"
ref="menubutton" ref="menubutton"
@ -21,6 +22,7 @@
<BarsIcon v-bind="ptm('menubuttonicon')" /> <BarsIcon v-bind="ptm('menubuttonicon')" />
</slot> </slot>
</a> </a>
</slot>
<MegaMenuSub <MegaMenuSub
:ref="menubarRef" :ref="menubarRef"
:id="id + '_list'" :id="id + '_list'"

View File

@ -83,13 +83,13 @@ export interface MenubarPassThroughOptions {
*/ */
separator?: MenubarPassThroughOptionType; separator?: MenubarPassThroughOptionType;
/** /**
* Used to pass attributes to the mobile popup menu button's DOM element. * Used to pass attributes to the mobile menu button's DOM element.
*/ */
button?: MenubarPassThroughOptionType; button?: MenubarPassThroughOptionType;
/** /**
* Used to pass attributes to the mobile popup menu button icon's DOM element. * Used to pass attributes to the mobile menu button icon's DOM element.
*/ */
popupIcon?: MenubarPassThroughOptionType; menubuttonicon?: MenubarPassThroughOptionType;
/** /**
* Used to pass attributes to the submenu's DOM element. * Used to pass attributes to the submenu's DOM element.
*/ */
@ -305,10 +305,34 @@ export interface MenubarSlots {
*/ */
hasSubmenu: boolean; hasSubmenu: boolean;
}): VNode[]; }): VNode[];
/**
* Custom menu button template on responsive mode.
* @param {Object} scope - menu button slot's params.
*/
menubutton(scope: {
/**
* Current id state as a string
*/
id: string;
/**
* Style class of component
*/
class: string;
/**
*
* Toggle event
*/
toggleCallback: () => void;
}): VNode[];
/** /**
* Custom popup icon template on responsive mode. * Custom popup icon template on responsive mode.
* @deprecated since v3.42.0. Use 'menubuttonicon' slot instead.
*/ */
popupicon(): VNode[]; popupicon(): VNode[];
/**
* Custom menu button icon template on responsive mode.
*/
menubuttonicon(): VNode[];
/** /**
* Custom submenu icon template. * Custom submenu icon template.
* @param {Object} scope - submenuicon slot's params. * @param {Object} scope - submenuicon slot's params.

View File

@ -3,6 +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="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"
@ -17,10 +18,11 @@
@keydown="menuButtonKeydown($event)" @keydown="menuButtonKeydown($event)"
v-bind="{ ...buttonProps, ...ptm('button') }" v-bind="{ ...buttonProps, ...ptm('button') }"
> >
<slot name="popupicon"> <slot name="menubuttonicon">
<BarsIcon v-bind="ptm('popupIcon')" /> <BarsIcon v-bind="ptm('menubuttonicon')" />
</slot> </slot>
</a> </a>
</slot>
<MenubarSub <MenubarSub
:ref="menubarRef" :ref="menubarRef"
:id="id" :id="id"
@ -422,10 +424,10 @@ export default {
bindOutsideClickListener() { bindOutsideClickListener() {
if (!this.outsideClickListener) { if (!this.outsideClickListener) {
this.outsideClickListener = (event) => { this.outsideClickListener = (event) => {
const isOutsideContainer = this.menubar && !this.menubar.contains(event.target); const isOutsideContainer = this.container && !this.container.contains(event.target);
const isOutsideMenuButton = this.mobileActive && this.$refs.menubutton ? this.$refs.menubutton !== event.target && !this.$refs.menubutton.contains(event.target) : true; const isOutsideTarget = !(this.target && (this.target === event.target || this.target.contains(event.target)));
if (isOutsideMenuButton && isOutsideContainer) { if (isOutsideContainer && isOutsideTarget) {
this.hide(); this.hide();
} }
}; };