@@ -66,6 +66,8 @@ export type MatTabBodyOriginState = 'left' | 'right';
66
66
export class MatTabBodyPortal extends CdkPortalOutlet implements OnInit , OnDestroy {
67
67
/** A subscription to events for when the tab body begins centering. */
68
68
private _centeringSub : Subscription ;
69
+ /** A subscription to events for when the tab body finishes leaving from center position. */
70
+ private _leavingSub : Subscription ;
69
71
70
72
constructor (
71
73
_componentFactoryResolver : ComponentFactoryResolver ,
@@ -84,17 +86,23 @@ export class MatTabBodyPortal extends CdkPortalOutlet implements OnInit, OnDestr
84
86
if ( ! this . hasAttached ( ) ) {
85
87
this . attach ( this . _host . _content ) ;
86
88
}
87
- } else {
88
- this . detach ( ) ;
89
89
}
90
90
} ) ;
91
+
92
+ this . _leavingSub = this . _host . _afterLeavingCenter . subscribe ( ( ) => {
93
+ this . detach ( ) ;
94
+ } ) ;
91
95
}
92
96
93
97
/** Clean up centering subscription. */
94
98
ngOnDestroy ( ) : void {
95
99
if ( this . _centeringSub && ! this . _centeringSub . closed ) {
96
100
this . _centeringSub . unsubscribe ( ) ;
97
101
}
102
+
103
+ if ( this . _leavingSub && ! this . _leavingSub . closed ) {
104
+ this . _leavingSub . unsubscribe ( ) ;
105
+ }
98
106
}
99
107
}
100
108
@@ -139,6 +147,9 @@ export class MatTabBody implements OnInit {
139
147
/** Event emitted before the centering of the tab begins. */
140
148
@Output ( ) _beforeCentering : EventEmitter < boolean > = new EventEmitter < boolean > ( ) ;
141
149
150
+ /** Event emitted before the centering of the tab begins. */
151
+ @Output ( ) _afterLeavingCenter : EventEmitter < boolean > = new EventEmitter < boolean > ( ) ;
152
+
142
153
/** Event emitted when the tab completes its animation towards the center. */
143
154
@Output ( ) _onCentered : EventEmitter < void > = new EventEmitter < void > ( true ) ;
144
155
@@ -198,6 +209,10 @@ export class MatTabBody implements OnInit {
198
209
if ( this . _isCenterPosition ( e . toState ) && this . _isCenterPosition ( this . _position ) ) {
199
210
this . _onCentered . emit ( ) ;
200
211
}
212
+
213
+ if ( this . _isCenterPosition ( e . fromState ) && ! this . _isCenterPosition ( this . _position ) ) {
214
+ this . _afterLeavingCenter . emit ( ) ;
215
+ }
201
216
}
202
217
203
218
/** The text direction of the containing app. */
0 commit comments