@@ -34,7 +34,8 @@ import {
34
34
import { DOCUMENT } from '@angular/platform-browser' ;
35
35
import { merge } from 'rxjs/observable/merge' ;
36
36
import { Subject } from 'rxjs/Subject' ;
37
- import { RxChain , filter , first , startWith , takeUntil } from '@angular/cdk/rxjs' ;
37
+ import { Observable } from 'rxjs/Observable' ;
38
+ import { RxChain , filter , map , first , startWith , takeUntil } from '@angular/cdk/rxjs' ;
38
39
39
40
40
41
/** Throws an exception when two MatDrawer are matching the same position. */
@@ -177,11 +178,38 @@ export class MatDrawer implements AfterContentInit, OnDestroy {
177
178
/** Current state of the sidenav animation. */
178
179
_animationState : 'open-instant' | 'open' | 'void' = 'void' ;
179
180
180
- /** Event emitted when the drawer is fully opened . */
181
- @Output ( 'open' ) onOpen = new EventEmitter < MatDrawerToggleResult | void > ( ) ;
181
+ /** Event emitted when the drawer open state is changed . */
182
+ @Output ( ) openedChange : EventEmitter < boolean > = new EventEmitter < boolean > ( ) ;
182
183
183
- /** Event emitted when the drawer is fully closed. */
184
- @Output ( 'close' ) onClose = new EventEmitter < MatDrawerToggleResult | void > ( ) ;
184
+ /** Event emitted when the drawer has been opened. */
185
+ @Output ( 'opened' )
186
+ get _openedStream ( ) : Observable < void > {
187
+ return RxChain . from ( this . openedChange )
188
+ . call ( filter , o => o )
189
+ . call ( map , ( ) => { } )
190
+ . result ( ) ;
191
+ }
192
+
193
+ /** Event emitted when the drawer has been closed. */
194
+ @Output ( 'closed' )
195
+ get _closedStream ( ) : Observable < void > {
196
+ return RxChain . from ( this . openedChange )
197
+ . call ( filter , o => ! o )
198
+ . call ( map , ( ) => { } )
199
+ . result ( ) ;
200
+ }
201
+
202
+ /**
203
+ * Event emitted when the drawer is fully opened.
204
+ * @deprecated Use `openedChange` instead.
205
+ */
206
+ @Output ( 'open' ) onOpen = this . _openedStream ;
207
+
208
+ /**
209
+ * Event emitted when the drawer is fully closed.
210
+ * @deprecated Use `openedChange` instead.
211
+ */
212
+ @Output ( 'close' ) onClose = this . _closedStream ;
185
213
186
214
/** Event emitted when the drawer's position changes. */
187
215
@Output ( 'positionChanged' ) onPositionChanged = new EventEmitter < void > ( ) ;
@@ -203,17 +231,19 @@ export class MatDrawer implements AfterContentInit, OnDestroy {
203
231
constructor ( private _elementRef : ElementRef ,
204
232
private _focusTrapFactory : FocusTrapFactory ,
205
233
@Optional ( ) @Inject ( DOCUMENT ) private _doc : any ) {
206
- this . onOpen . subscribe ( ( ) => {
207
- if ( this . _doc ) {
208
- this . _elementFocusedBeforeDrawerWasOpened = this . _doc . activeElement as HTMLElement ;
209
- }
234
+ this . openedChange . subscribe ( ( opened : boolean ) => {
235
+ if ( opened ) {
236
+ if ( this . _doc ) {
237
+ this . _elementFocusedBeforeDrawerWasOpened = this . _doc . activeElement as HTMLElement ;
238
+ }
210
239
211
- if ( this . _isFocusTrapEnabled && this . _focusTrap ) {
212
- this . _focusTrap . focusInitialElementWhenReady ( ) ;
240
+ if ( this . _isFocusTrapEnabled && this . _focusTrap ) {
241
+ this . _focusTrap . focusInitialElementWhenReady ( ) ;
242
+ }
243
+ } else {
244
+ this . _restoreFocus ( ) ;
213
245
}
214
246
} ) ;
215
-
216
- this . onClose . subscribe ( ( ) => this . _restoreFocus ( ) ) ;
217
247
}
218
248
219
249
/**
@@ -309,9 +339,9 @@ export class MatDrawer implements AfterContentInit, OnDestroy {
309
339
const { fromState, toState} = event ;
310
340
311
341
if ( toState . indexOf ( 'open' ) === 0 && fromState === 'void' ) {
312
- this . onOpen . emit ( new MatDrawerToggleResult ( 'open' , true ) ) ;
342
+ this . openedChange . emit ( true ) ;
313
343
} else if ( toState === 'void' && fromState . indexOf ( 'open' ) === 0 ) {
314
- this . onClose . emit ( new MatDrawerToggleResult ( 'close' , true ) ) ;
344
+ this . openedChange . emit ( false ) ;
315
345
}
316
346
}
317
347
@@ -438,7 +468,7 @@ export class MatDrawerContainer implements AfterContentInit, OnDestroy {
438
468
} ) ;
439
469
440
470
if ( drawer . mode !== 'side' ) {
441
- takeUntil . call ( merge ( drawer . onOpen , drawer . onClose ) , this . _drawers . changes ) . subscribe ( ( ) =>
471
+ takeUntil . call ( drawer . openedChange , this . _drawers . changes ) . subscribe ( ( ) =>
442
472
this . _setContainerClass ( drawer . opened ) ) ;
443
473
}
444
474
}
0 commit comments