Skip to content
This repository was archived by the owner on Nov 12, 2025. It is now read-only.

Commit 800fffd

Browse files
authored
feat(vertical-navigation): added showMenuCollapsed attribute (#441)
This allows developers to maintain collapsed state, for the hamburger menu, should the page be refreshed.
1 parent 12a35ba commit 800fffd

File tree

2 files changed

+32
-12
lines changed

2 files changed

+32
-12
lines changed

src/app/navigation/vertical-navigation/vertical-navigation.component.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,16 @@ describe('Vertical Navigation component - ', () => {
615615
expect(badgesShown).toBeNull();
616616
});
617617

618+
it('should show initially collapsed menu', function() {
619+
let badgesMenu = fixture.debugElement.query(By.css('.nav-pf-vertical.nav-pf-vertical-with-badges.collapsed'));
620+
expect(badgesMenu).toBeNull();
621+
622+
comp.showMenuCollapsed = true;
623+
fixture.detectChanges();
624+
625+
badgesMenu = fixture.debugElement.query(By.css('.nav-pf-vertical-with-badges.collapsed'));
626+
expect(badgesMenu).toBeNull();
627+
});
618628
});
619629

620630

src/app/navigation/vertical-navigation/vertical-navigation.component.ts

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,14 @@ export class VerticalNavigationComponent implements OnInit, OnDestroy {
5656
@Input() contentContainer: HTMLElement;
5757

5858
/**
59-
* Boolean to indicate whether or not to show badges, default: false
59+
* Indicates whether or not this is a mobile friendly navigation, default: false
6060
*/
61-
@Input() showBadges: boolean = false;
61+
@Input() ignoreMobile: boolean = false;
62+
63+
/**
64+
* The navigation items used to build the menu
65+
*/
66+
@Input() items: VerticalNavigationItem[];
6267

6368
/**
6469
* Indicates whether or not to allow the secondary to persist, default: false
@@ -71,29 +76,31 @@ export class VerticalNavigationComponent implements OnInit, OnDestroy {
7176
@Input() pinnableMenus: boolean = false;
7277

7378
/**
74-
* Show menu icons, default: true
79+
* Boolean to indicate whether or not to show badges, default: false
7580
*/
76-
@Input() showIcons: boolean = true;
81+
@Input() showBadges: boolean = false;
7782

7883
/**
79-
* The navigation items used to build the menu
84+
* Show menu icons, default: true
8085
*/
81-
@Input() items: VerticalNavigationItem[];
86+
@Input() showIcons: boolean = true;
8287

8388
/**
84-
* Sets an active flag on items when they are selected, default: false
89+
* Boolean indicating menu is shown initially collapsed
90+
*
91+
* Note that this does not apply for the mobile state
8592
*/
86-
@Input() updateActiveItemsOnClick: boolean = false;
93+
@Input() showMenuCollapsed: boolean = false;
8794

8895
/**
89-
* Indicates whether or not this is a mobile friendly navigation, default: false
96+
* Show top banner, default: true
9097
*/
91-
@Input() ignoreMobile: boolean = false;
98+
@Input() showTopBanner: boolean = true;
9299

93100
/**
94-
* Show top banner, default: true
101+
* Sets an active flag on items when they are selected, default: false
95102
*/
96-
@Input() showTopBanner: boolean = true;
103+
@Input() updateActiveItemsOnClick: boolean = false;
97104

98105
/**
99106
* This event is fired any time the user has initiated navigation
@@ -160,6 +167,9 @@ export class VerticalNavigationComponent implements OnInit, OnDestroy {
160167
this.initActiveItems();
161168
}
162169

170+
if (this.showMenuCollapsed !== undefined) {
171+
this.explicitCollapse = this.showMenuCollapsed;
172+
}
163173
this.initBodyElement();
164174
this.checkNavState();
165175
}

0 commit comments

Comments
 (0)