Skip to content

Commit cdae565

Browse files
committed
feat(aio): close sidenav in narrow (mobile) mode when select a new document
closes #16603 As before this PR, when wide (side-by-side), the sidenav open/close status only changes when nav to/from marketing page in which case it opens for guide/api and closes for marketing page.
1 parent 5cf6426 commit cdae565

2 files changed

Lines changed: 17 additions & 12 deletions

File tree

‎aio/src/app/app.component.spec.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,13 @@ describe('AppComponent', () => {
118118
expect(sidenav.className).toMatch(/sidenav-clos/);
119119
});
120120

121-
it('should stay closed when nav to another guide page', () => {
121+
it('should stay closed when nav from one guide page to another', () => {
122122
locationService.go('guide/bags');
123123
fixture.detectChanges();
124124
expect(sidenav.className).toMatch(/sidenav-clos/);
125125
});
126126

127-
it('should stay closed when nav to api page', () => {
127+
it('should stay closed when nav from a guide page to api page', () => {
128128
locationService.go('api');
129129
fixture.detectChanges();
130130
expect(sidenav.className).toMatch(/sidenav-clos/);
@@ -184,16 +184,16 @@ describe('AppComponent', () => {
184184
expect(sidenav.className).toMatch(/sidenav-clos/);
185185
});
186186

187-
it('should stay open when nav to another guide page', () => {
187+
it('should close when nav to another guide page', () => {
188188
locationService.go('guide/bags');
189189
fixture.detectChanges();
190-
expect(sidenav.className).toMatch(/sidenav-open/);
190+
expect(sidenav.className).toMatch(/sidenav-clos/);
191191
});
192192

193-
it('should stay open when nav to api page', () => {
193+
it('should close when nav to api page', () => {
194194
locationService.go('api');
195195
fixture.detectChanges();
196-
expect(sidenav.className).toMatch(/sidenav-open/);
196+
expect(sidenav.className).toMatch(/sidenav-clos/);
197197
});
198198

199199
it('should close again when nav to market page', () => {

‎aio/src/app/app.component.ts‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,18 @@ export class AppComponent implements OnInit {
116116

117117
this.navigationService.currentNode.subscribe(currentNode => {
118118
this.currentNode = currentNode;
119-
this.updateHostClasses();
120119

121-
// Toggle the sidenav if side-by-side and the kind of view changed
122-
if (this.previousNavView === currentNode.view) { return; }
123-
this.previousNavView = currentNode.view;
124-
this.isSideNavDoc = currentNode.view === sideNavView;
125-
this.sideNavToggle(this.isSideNavDoc && this.isSideBySide);
120+
// Preserve current sidenav open state by default
121+
let openSideNav = this.sidenav.opened;
122+
123+
if (this.previousNavView !== currentNode.view) {
124+
this.previousNavView = currentNode.view;
125+
// View type changed. Is it now a sidenav view (e.g, guide or tutorial)?
126+
// Open if changed to a sidenav doc; close if changed to a marketing doc.
127+
openSideNav = this.isSideNavDoc = currentNode.view === sideNavView;
128+
}
129+
// May be open or closed when wide; always closed when narrow
130+
this.sideNavToggle(this.isSideBySide ? openSideNav : false);
126131
});
127132

128133
this.navigationService.navigationViews.subscribe(views => {

0 commit comments

Comments
 (0)