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

feat(menu): permite habilitar o automatic toggle #1909

Merged
merged 1 commit into from
Jan 12, 2024
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
11 changes: 11 additions & 0 deletions projects/ui/src/lib/components/po-menu/po-menu-base.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@ export abstract class PoMenuBaseComponent {
private _params: any;
private _service: string | PoMenuFilter;

/**
* @optional
*
* @description
*
* Expande e Colapsa (retrai) o menu automaticamente.
*
* @default `false`
*/
@Input({ alias: 'p-automatic-toggle', transform: convertToBoolean }) automaticToggle: boolean = false;

/**
* @optional
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,7 @@ describe('PoMenuComponent:', () => {
it('should set "collapsed" to false and "allowCollapseHover" to true when onMouseEnter is called and the component is collapsed', () => {
component.collapsed = true;
component.allowCollapseHover = false;
component.automaticToggle = true;

component.onMouseEnter();

Expand All @@ -946,6 +947,7 @@ describe('PoMenuComponent:', () => {
it('should not modify the "collapsed" or "allowCollapseHover" state when onMouseEnter is called and the component is not collapsed', () => {
component.collapsed = false;
component.allowCollapseHover = true;
component.automaticToggle = true;

component.onMouseEnter();

Expand All @@ -956,6 +958,7 @@ describe('PoMenuComponent:', () => {
it('should set "collapsed" to true when onMouseLeave is called and the component is not collapsed and allowCollapseHover is true', () => {
component.collapsed = false;
component.allowCollapseHover = true;
component.automaticToggle = true;

component.onMouseLeave();

Expand All @@ -965,6 +968,7 @@ describe('PoMenuComponent:', () => {
it('should not modify the "collapsed" state when onMouseLeave is called and the component is already collapsed', () => {
component.collapsed = true;
component.allowCollapseHover = true;
component.automaticToggle = true;

component.onMouseLeave();

Expand All @@ -974,6 +978,7 @@ describe('PoMenuComponent:', () => {
it('should not modify the "collapsed" state when onMouseLeave is called and allowCollapseHover is false', () => {
component.collapsed = false;
component.allowCollapseHover = false;
component.automaticToggle = true;

component.onMouseLeave();

Expand Down
4 changes: 2 additions & 2 deletions projects/ui/src/lib/components/po-menu/po-menu.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,14 +298,14 @@ export class PoMenuComponent extends PoMenuBaseComponent implements AfterViewIni
}

onMouseEnter(): void {
if (this.collapsed) {
if (this.collapsed && this.automaticToggle) {
this.collapsed = false;
this.allowCollapseHover = true;
}
}

onMouseLeave(): void {
if (!this.collapsed && this.allowCollapseHover) {
if (!this.collapsed && this.allowCollapseHover && this.automaticToggle) {
this.collapsed = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<div class="po-wrapper">
<po-menu p-collapsed p-filter [p-menus]="menus" [p-service]="samplePoMenuHumanResourcesService">
<po-menu
p-collapsed
p-filter
[p-menus]="menus"
[p-service]="samplePoMenuHumanResourcesService"
[p-automatic-toggle]="true"
>
<div *p-menu-header-template class="po-p-2 po-font-title sample-menu-header-text-color">
<p>Welcome,</p>
<p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import { ChangeDetectorRef, Component, OnInit, ViewChild } from '@angular/core';

import {
PoButtonGroupItem,
PoMenuComponent,
PoMenuItem,
PoRadioGroupOption,
PoSelectOption
} from '@po-ui/ng-components';
import { PoButtonGroupItem, PoMenuComponent, PoMenuItem, PoSelectOption } from '@po-ui/ng-components';

@Component({
selector: 'sample-po-menu-labs',
Expand Down