Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MenuBar Behaviour Fixed #8256

Merged
merged 1 commit into from
Oct 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 35 additions & 35 deletions src/app/components/menubar/menubar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { RouterModule } from '@angular/router';
<li *ngIf="child.separator" class="ui-menu-separator ui-widget-content" [ngClass]="{'ui-helper-hidden': child.visible === false}">
<li *ngIf="!child.separator" #listItem [ngClass]="{'ui-menuitem ui-corner-all':true,
'ui-menu-parent':child.items,'ui-menuitem-active':listItem==activeItem,'ui-helper-hidden': child.visible === false}"
(mouseenter)="onItemMouseEnter($event,listItem,child)" (mouseleave)="onItemMouseLeave($event)" (click)="onItemMenuClick($event, listItem, child)">
(mouseenter)="onItemMouseEnter($event,listItem,child)" (click)="onItemMenuClick($event, listItem, child)">
<a *ngIf="!child.routerLink" [href]="child.url||'#'" [attr.data-automationid]="child.automationId" [attr.target]="child.target" [attr.title]="child.title" [attr.id]="child.id" (click)="itemClick($event, child)"
[ngClass]="{'ui-menuitem-link ui-corner-all':true,'ui-state-disabled':child.disabled}" [ngStyle]="child.style" [class]="child.styleClass" [attr.tabindex]="child.tabindex ? child.tabindex : '0'">
<span class="ui-menuitem-icon" *ngIf="child.icon" [ngClass]="child.icon"></span>
Expand All @@ -27,7 +27,7 @@ import { RouterModule } from '@angular/router';
<span class="ui-menuitem-text">{{child.label}}</span>
<span class="ui-submenu-icon pi pi-fw" *ngIf="child.items" [ngClass]="{'pi-caret-down':root,'pi-caret-right':!root}"></span>
</a>
<p-menubarSub class="ui-submenu" [item]="child" *ngIf="child.items" [autoDisplay]="true"></p-menubarSub>
<p-menubarSub class="ui-submenu" [parentActive]="listItem==activeItem" [item]="child" *ngIf="child.items" [autoDisplay]="true"></p-menubarSub>
</li>
</ng-template>
</ul>
Expand All @@ -45,6 +45,21 @@ export class MenubarSub implements OnDestroy {

@Input() baseZIndex: number = 0;

@Input() get parentActive():boolean
{
return this._parentActive;
}
set parentActive(value) {
if (!this.root) {
this._parentActive = value;

if (!value)
this.activeItem = null;
}
}

_parentActive:boolean;

documentClickListener: any;

menuClick: boolean;
Expand All @@ -53,8 +68,6 @@ export class MenubarSub implements OnDestroy {

activeItem: any;

hideTimeout: any;

activeMenu: any;

constructor(public renderer: Renderer2, private cd: ChangeDetectorRef) { }
Expand Down Expand Up @@ -96,6 +109,7 @@ export class MenubarSub implements OnDestroy {
if (!this.menuClick) {
this.activeItem = null;
this.menuHoverActive = false;
this.activeMenu = false;
}
this.menuClick = false;
});
Expand All @@ -108,39 +122,27 @@ export class MenubarSub implements OnDestroy {
return;
}

if(this.hideTimeout) {
clearTimeout(this.hideTimeout);
this.hideTimeout = null;
}

this.activeItem = this.activeItem ? (this.activeItem.isEqualNode(item) && this.autoDisplay ? null: item) : item;
let nextElement = <HTMLLIElement>item.children[0].nextElementSibling;
if (nextElement) {
let sublist = <HTMLUListElement>nextElement.children[0];
sublist.style.zIndex = String(++DomHandler.zindex);

if (this.root) {
sublist.style.top = DomHandler.getOuterHeight(item.children[0]) + 'px';
sublist.style.left = '0px'
}
else {
sublist.style.top = '0px';
sublist.style.left = DomHandler.getOuterWidth(item.children[0]) + 'px';
if ((this.activeItem && !this.activeItem.isEqualNode(item) || !this.activeItem)) {
this.activeItem = item;
let nextElement = <HTMLLIElement>item.children[0].nextElementSibling;
if (nextElement) {
let sublist = <HTMLUListElement>nextElement.children[0];
sublist.style.zIndex = String(++DomHandler.zindex);

if (this.root) {
sublist.style.top = DomHandler.getOuterHeight(item.children[0]) + 'px';
sublist.style.left = '0px'
}
else {
sublist.style.top = '0px';
sublist.style.left = DomHandler.getOuterWidth(item.children[0]) + 'px';
}
}
this.activeMenu = item;
}

this.activeMenu = this.activeMenu ? (this.activeMenu.isEqualNode(item) && this.autoDisplay ? null: item) : item;
}
}

onItemMouseLeave(event: Event) {
if (this.autoDisplay) {
this.hideTimeout = setTimeout(() => {
this.activeItem = null;
this.cd.markForCheck();
}, 250);
}
}

itemClick(event, item: MenuItem)  {
if (item.disabled) {
Expand Down Expand Up @@ -182,7 +184,7 @@ export class MenubarSub implements OnDestroy {
selector: 'p-menubar',
template: `
<div [ngClass]="{'ui-menubar ui-widget ui-widget-content ui-corner-all':true}" [class]="styleClass" [ngStyle]="style">
<p-menubarSub [item]="model" root="root" [autoDisplay]="autoDisplay" [baseZIndex]="baseZIndex" [autoZIndex]="autoZIndex">
<p-menubarSub [item]="model" root="root" [baseZIndex]="baseZIndex" [autoZIndex]="autoZIndex">
<ng-content></ng-content>
</p-menubarSub>
<div class="ui-menubar-custom">
Expand All @@ -199,8 +201,6 @@ export class Menubar {

@Input() styleClass: string;

@Input() autoDisplay: boolean = true;

@Input() autoZIndex: boolean = true;

@Input() baseZIndex: number = 0;
Expand Down
21 changes: 0 additions & 21 deletions src/app/showcase/components/menubar/menubardemo.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,12 @@
</div>

<div class="content-section implementation">
<h3 class="first">With AutoDisplay</h3>
<p-menubar [model]="items">
<div>
<input type="text" pInputText placeholder="Search">
<button pButton label="Logout" icon="fa fa-sign-out" style="margin-left:.25em"></button>
</div>
</p-menubar>

<h3>Without AutoDisplay</h3>
<p-menubar [model]="items" [autoDisplay]="false">
<div>
<input type="text" pInputText placeholder="Search">
<button pButton label="Logout" icon="fa fa-sign-out" style="margin-left:.25em"></button>
</div>
</p-menubar>
</div>

<div class="content-section documentation">
Expand Down Expand Up @@ -111,12 +102,6 @@ <h3>Properties</h3>
<td>null</td>
<td>An array of menuitems.</td>
</tr>
<tr>
<td>autoDisplay</td>
<td>boolean</td>
<td>true</td>
<td>Display menu item when mouse enter or display menu item when clicked</td>
</tr>
<tr>
<td>style</td>
<td>string</td>
Expand Down Expand Up @@ -201,12 +186,6 @@ <h3>Dependencies</h3>
&lt;button pButton label="Logout" icon="fa fa-sign-out" style="margin-left:.25em"&gt;&lt;/button&gt;
&lt;/div&gt;
&lt;/p-menubar&gt;
&lt;p-menubar [model]="items" [autoDisplay]="false"&gt;
&lt;div&gt;
&lt;input type="text" pInputText placeholder="Search"&gt;
&lt;button pButton label="Logout" icon="fa fa-sign-out" style="margin-left:.25em"&gt;&lt;/button&gt;
&lt;/div&gt;
&lt;/p-menubar&gt;
</code>
</pre>

Expand Down