Skip to content

Commit

Permalink
feat(aio): close sidenav in narrow (mobile) mode when select a new do…
Browse files Browse the repository at this point in the history
…cument

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.
  • Loading branch information
wardbell committed May 7, 2017
1 parent 5cf6426 commit fcaecd2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
8 changes: 4 additions & 4 deletions aio/src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,16 +184,16 @@ describe('AppComponent', () => {
expect(sidenav.className).toMatch(/sidenav-clos/);
});

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

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

it('should close again when nav to market page', () => {
Expand Down
17 changes: 11 additions & 6 deletions aio/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,18 @@ export class AppComponent implements OnInit {

this.navigationService.currentNode.subscribe(currentNode => {
this.currentNode = currentNode;
this.updateHostClasses();

// Toggle the sidenav if side-by-side and the kind of view changed
if (this.previousNavView === currentNode.view) { return; }
this.previousNavView = currentNode.view;
this.isSideNavDoc = currentNode.view === sideNavView;
this.sideNavToggle(this.isSideNavDoc && this.isSideBySide);
// Preserve current sidenav open state by default
let openSideNav = this.sidenav.opened;

if (this.previousNavView !== currentNode.view) {
this.previousNavView = currentNode.view;
// View type changed. Is it now a sidenav view (e.g, guide or tutorial)?
// Open if changed to a sidenav doc; close if changed to a marketing doc.
openSideNav = this.isSideNavDoc = currentNode.view === sideNavView;
}
// May be open or closed when wide; always closed when narrow
this.sideNavToggle(this.isSideBySide ? openSideNav : false);
});

this.navigationService.navigationViews.subscribe(views => {
Expand Down

0 comments on commit fcaecd2

Please sign in to comment.