88
99import {
1010 AfterContentInit ,
11+ ChangeDetectionStrategy ,
12+ ChangeDetectorRef ,
1113 Component ,
14+ ContentChild ,
1215 ContentChildren ,
1316 ElementRef ,
17+ EventEmitter ,
18+ forwardRef ,
19+ Inject ,
1420 Input ,
21+ NgZone ,
22+ OnDestroy ,
1523 Optional ,
1624 Output ,
1725 QueryList ,
18- ChangeDetectionStrategy ,
19- EventEmitter ,
2026 Renderer2 ,
2127 ViewEncapsulation ,
22- NgZone ,
23- OnDestroy ,
24- Inject ,
25- ChangeDetectorRef , ContentChild , forwardRef ,
2628} from '@angular/core' ;
27- import { animate , state , style , transition , trigger , AnimationEvent } from '@angular/animations' ;
28- import { Directionality , coerceBooleanProperty } from '../core' ;
29- import { FocusTrapFactory , FocusTrap } from '../core/a11y/focus-trap' ;
29+ import { animate , AnimationEvent , state , style , transition , trigger } from '@angular/animations' ;
30+ import { coerceBooleanProperty , Directionality } from '../core' ;
31+ import { FocusTrap , FocusTrapFactory } from '../core/a11y/focus-trap' ;
3032import { ESCAPE } from '../core/keyboard/keycodes' ;
31- import { first , takeUntil , startWith } from '../core/rxjs/index' ;
33+ import { first , startWith , takeUntil } from '../core/rxjs/index' ;
3234import { DOCUMENT } from '@angular/platform-browser' ;
3335import { merge } from 'rxjs/observable/merge' ;
3436import { Subject } from 'rxjs/Subject' ;
@@ -62,7 +64,11 @@ export class MdDrawerToggleResult {
6264 encapsulation : ViewEncapsulation . None ,
6365} )
6466export class MdDrawerContent implements AfterContentInit {
65- /** Margins to be applied to the content. */
67+ /**
68+ * Margins to be applied to the content. These are used to push / shrink the drawer content when a
69+ * drawer is open. We use margin rather than transform even for push mode because transform breaks
70+ * fixed position elements inside of the transformed element.
71+ */
6672 _margins : { left : number , right : number } = { left : 0 , right : 0 } ;
6773
6874 constructor (
@@ -71,7 +77,7 @@ export class MdDrawerContent implements AfterContentInit {
7177 }
7278
7379 ngAfterContentInit ( ) {
74- this . _container . _contentMargins . subscribe ( ( margins ) => {
80+ this . _container . _contentMargins . subscribe ( margins => {
7581 this . _margins = margins ;
7682 this . _changeDetectorRef . markForCheck ( ) ;
7783 } ) ;
@@ -193,6 +199,10 @@ export class MdDrawer implements AfterContentInit, OnDestroy {
193199 /** @deprecated */
194200 @Output ( 'align-changed' ) onAlignChanged = new EventEmitter < void > ( ) ;
195201
202+ /**
203+ * An observable that emits when the drawer mode changes. This is used by the drawer container to
204+ * to know when to when the mode changes so it can adapt the margins on the content.
205+ */
196206 _modeChanged = new Subject ( ) ;
197207
198208 get isFocusTrapEnabled ( ) {
@@ -524,6 +534,13 @@ export class MdDrawerContainer implements AfterContentInit {
524534 * sparingly, because it causes a reflow.
525535 */
526536 private _updateContentMargins ( ) {
537+ // 1. For drawers in `over` mode, they don't affect the content.
538+ // 2. For drawers in `side` mode they should shrink the content. We do this by adding to the
539+ // left margin (for left drawer) or right margin (for right the drawer).
540+ // 3. For drawers in `push` mode the should shift the content without resizing it. We do this by
541+ // adding to the left or right margin and simultaneously subtracting the same amount of
542+ // margin from the other side.
543+
527544 let left = 0 ;
528545 let right = 0 ;
529546
0 commit comments