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 (angular#16617)

closes angular#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 authored and Zhicheng Wang committed Aug 11, 2017
1 parent 0dcaf9f commit 145167c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
12 changes: 6 additions & 6 deletions aio/src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,13 @@ describe('AppComponent', () => {
expect(sidenav.className).toMatch(/sidenav-clos/);
});

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

it('should stay closed when nav to api page', () => {
it('should stay closed when nav from a guide page to api page', () => {
locationService.go('api');
fixture.detectChanges();
expect(sidenav.className).toMatch(/sidenav-clos/);
Expand Down 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 145167c

Please sign in to comment.