Skip to content
This repository was archived by the owner on Dec 18, 2024. It is now read-only.

Commit 9826360

Browse files
josephperrottjelbourn
authored andcommitted
Place MediaQueryList updates back in angular zone, fixing autohiding of sidenav. (#242)
1 parent 5d7429d commit 9826360

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/app/pages/component-sidenav/component-sidenav.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Component, ViewEncapsulation, ViewChild, OnInit, NgModule} from '@angular/core';
1+
import {Component, NgZone, ViewEncapsulation, ViewChild, OnInit, NgModule} from '@angular/core';
22
import {DocumentationItems} from '../../shared/documentation-items/documentation-items';
33
import {MdSidenav, MdSidenavModule} from '@angular/material';
44
import {Router, RouterModule} from '@angular/router';
@@ -15,8 +15,14 @@ const SMALL_WIDTH_BREAKPOINT = 840;
1515
encapsulation: ViewEncapsulation.None,
1616
})
1717
export class ComponentSidenav implements OnInit {
18+
private mediaMatcher: MediaQueryList = matchMedia(`(max-width: ${SMALL_WIDTH_BREAKPOINT}px)`);
19+
1820
constructor(public docItems: DocumentationItems,
19-
private _router: Router) {}
21+
private _router: Router,
22+
zone: NgZone) {
23+
// TODO(josephperrott): Move to CDK breakpoint management once available.
24+
this.mediaMatcher.addListener(mql => zone.run(() => this.mediaMatcher = mql));
25+
}
2026

2127
@ViewChild(MdSidenav) sidenav: MdSidenav;
2228

@@ -29,7 +35,7 @@ export class ComponentSidenav implements OnInit {
2935
}
3036

3137
isScreenSmall(): boolean {
32-
return window.matchMedia(`(max-width: ${SMALL_WIDTH_BREAKPOINT}px)`).matches;
38+
return this.mediaMatcher.matches;
3339
}
3440
}
3541

0 commit comments

Comments
 (0)