8
8
9
9
import {
10
10
AfterContentInit ,
11
+ ChangeDetectionStrategy ,
12
+ ChangeDetectorRef ,
11
13
Component ,
14
+ ContentChild ,
12
15
ContentChildren ,
13
16
ElementRef ,
17
+ EventEmitter ,
18
+ forwardRef ,
19
+ Inject ,
14
20
Input ,
21
+ NgZone ,
22
+ OnDestroy ,
15
23
Optional ,
16
24
Output ,
17
25
QueryList ,
18
- ChangeDetectionStrategy ,
19
- EventEmitter ,
20
26
Renderer2 ,
21
27
ViewEncapsulation ,
22
- NgZone ,
23
- OnDestroy ,
24
- Inject ,
25
- ChangeDetectorRef , ContentChild , forwardRef ,
26
28
} 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' ;
30
32
import { ESCAPE } from '../core/keyboard/keycodes' ;
31
- import { first , takeUntil , startWith } from '../core/rxjs/index' ;
33
+ import { first , startWith , takeUntil } from '../core/rxjs/index' ;
32
34
import { DOCUMENT } from '@angular/platform-browser' ;
33
35
import { merge } from 'rxjs/observable/merge' ;
34
36
import { Subscription } from 'rxjs/Subscription' ;
@@ -63,7 +65,11 @@ export class MdDrawerToggleResult {
63
65
encapsulation : ViewEncapsulation . None ,
64
66
} )
65
67
export class MdDrawerContent implements AfterContentInit {
66
- /** Margins to be applied to the content. */
68
+ /**
69
+ * Margins to be applied to the content. These are used to push / shrink the drawer content when a
70
+ * drawer is open. We use margin rather than transform even for push mode because transform breaks
71
+ * fixed position elements inside of the transformed element.
72
+ */
67
73
_margins : { left : number , right : number } = { left : 0 , right : 0 } ;
68
74
69
75
constructor (
@@ -72,7 +78,7 @@ export class MdDrawerContent implements AfterContentInit {
72
78
}
73
79
74
80
ngAfterContentInit ( ) {
75
- this . _container . _contentMargins . subscribe ( ( margins ) => {
81
+ this . _container . _contentMargins . subscribe ( margins => {
76
82
this . _margins = margins ;
77
83
this . _changeDetectorRef . markForCheck ( ) ;
78
84
} ) ;
@@ -194,6 +200,10 @@ export class MdDrawer implements AfterContentInit, OnDestroy {
194
200
/** @deprecated */
195
201
@Output ( 'align-changed' ) onAlignChanged = new EventEmitter < void > ( ) ;
196
202
203
+ /**
204
+ * An observable that emits when the drawer mode changes. This is used by the drawer container to
205
+ * to know when to when the mode changes so it can adapt the margins on the content.
206
+ */
197
207
_modeChanged = new Subject ( ) ;
198
208
199
209
get isFocusTrapEnabled ( ) {
@@ -532,6 +542,13 @@ export class MdDrawerContainer implements AfterContentInit, OnDestroy {
532
542
* sparingly, because it causes a reflow.
533
543
*/
534
544
private _updateContentMargins ( ) {
545
+ // 1. For drawers in `over` mode, they don't affect the content.
546
+ // 2. For drawers in `side` mode they should shrink the content. We do this by adding to the
547
+ // left margin (for left drawer) or right margin (for right the drawer).
548
+ // 3. For drawers in `push` mode the should shift the content without resizing it. We do this by
549
+ // adding to the left or right margin and simultaneously subtracting the same amount of
550
+ // margin from the other side.
551
+
535
552
let left = 0 ;
536
553
let right = 0 ;
537
554
0 commit comments