Skip to content

Commit

Permalink
Fixed #4862 - MegaMenu / Menubar: menubutton templating
Browse files Browse the repository at this point in the history
  • Loading branch information
tugcekucukoglu committed Nov 22, 2023
1 parent dd2f455 commit 7d86b48
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 42 deletions.
23 changes: 23 additions & 0 deletions components/lib/megamenu/MegaMenu.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,29 @@ export interface MegaMenuSlots {
*/
hasSubmenu: boolean;
}): 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.
* @param {Object} scope - submenuicon slot's params.
Expand Down
38 changes: 20 additions & 18 deletions components/lib/megamenu/MegaMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,26 @@
<div v-if="$slots.start" :class="cx('start')" v-bind="ptm('start')">
<slot name="start"></slot>
</div>
<a
v-if="model && model.length > 0"
ref="menubutton"
role="button"
tabindex="0"
:class="cx('menubutton')"
:aria-haspopup="model.length && model.length > 0 ? true : false"
:aria-expanded="mobileActive"
:aria-controls="id"
:aria-label="$primevue.config.locale.aria?.navigation"
@click="menuButtonClick($event)"
@keydown="menuButtonKeydown($event)"
v-bind="ptm('menubutton')"
>
<slot name="menubuttonicon">
<BarsIcon v-bind="ptm('menubuttonicon')" />
</slot>
</a>
<slot :id="id" name="menubutton" :class="cx('menubutton')" :toggleCallback="(event) => menuButtonClick(event)">
<a
v-if="model && model.length > 0"
ref="menubutton"
role="button"
tabindex="0"
:class="cx('menubutton')"
:aria-haspopup="model.length && model.length > 0 ? true : false"
:aria-expanded="mobileActive"
:aria-controls="id"
:aria-label="$primevue.config.locale.aria?.navigation"
@click="menuButtonClick($event)"
@keydown="menuButtonKeydown($event)"
v-bind="ptm('menubutton')"
>
<slot name="menubuttonicon">
<BarsIcon v-bind="ptm('menubuttonicon')" />
</slot>
</a>
</slot>
<MegaMenuSub
:ref="menubarRef"
:id="id + '_list'"
Expand Down
30 changes: 27 additions & 3 deletions components/lib/menubar/Menubar.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ export interface MenubarPassThroughOptions {
*/
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;
/**
* 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.
*/
Expand Down Expand Up @@ -305,10 +305,34 @@ export interface MenubarSlots {
*/
hasSubmenu: boolean;
}): 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.
* @deprecated since v3.42.0. Use 'menubuttonicon' slot instead.
*/
popupicon(): VNode[];
/**
* Custom menu button icon template on responsive mode.
*/
menubuttonicon(): VNode[];
/**
* Custom submenu icon template.
* @param {Object} scope - submenuicon slot's params.
Expand Down
44 changes: 23 additions & 21 deletions components/lib/menubar/Menubar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,26 @@
<div v-if="$slots.start" :class="cx('start')" v-bind="ptm('start')">
<slot name="start"></slot>
</div>
<a
v-if="model && model.length > 0"
ref="menubutton"
role="button"
tabindex="0"
:class="cx('button')"
:aria-haspopup="model.length && model.length > 0 ? true : false"
:aria-expanded="mobileActive"
:aria-controls="id"
:aria-label="$primevue.config.locale.aria?.navigation"
@click="menuButtonClick($event)"
@keydown="menuButtonKeydown($event)"
v-bind="{ ...buttonProps, ...ptm('button') }"
>
<slot name="popupicon">
<BarsIcon v-bind="ptm('popupIcon')" />
</slot>
</a>
<slot :id="id" name="menubutton" :class="cx('button')" :toggleCallback="(event) => menuButtonClick(event)">
<a
v-if="model && model.length > 0"
ref="menubutton"
role="button"
tabindex="0"
:class="cx('button')"
:aria-haspopup="model.length && model.length > 0 ? true : false"
:aria-expanded="mobileActive"
:aria-controls="id"
:aria-label="$primevue.config.locale.aria?.navigation"
@click="menuButtonClick($event)"
@keydown="menuButtonKeydown($event)"
v-bind="{ ...buttonProps, ...ptm('button') }"
>
<slot name="menubuttonicon">
<BarsIcon v-bind="ptm('menubuttonicon')" />
</slot>
</a>
</slot>
<MenubarSub
:ref="menubarRef"
:id="id"
Expand Down Expand Up @@ -422,10 +424,10 @@ export default {
bindOutsideClickListener() {
if (!this.outsideClickListener) {
this.outsideClickListener = (event) => {
const isOutsideContainer = this.menubar && !this.menubar.contains(event.target);
const isOutsideMenuButton = this.mobileActive && this.$refs.menubutton ? this.$refs.menubutton !== event.target && !this.$refs.menubutton.contains(event.target) : true;
const isOutsideContainer = this.container && !this.container.contains(event.target);
const isOutsideTarget = !(this.target && (this.target === event.target || this.target.contains(event.target)));
if (isOutsideMenuButton && isOutsideContainer) {
if (isOutsideContainer && isOutsideTarget) {
this.hide();
}
};
Expand Down

0 comments on commit 7d86b48

Please sign in to comment.