@@ -91,14 +91,20 @@ export class MdTabBody implements OnInit, AfterViewChecked {
91
91
/** The portal host inside of this container into which the tab body content will be loaded. */
92
92
@ViewChild ( PortalHostDirective ) _portalHost : PortalHostDirective ;
93
93
94
+ /** Element wrapping the tab's content. */
95
+ @ViewChild ( 'content' ) _contentElement : ElementRef ;
96
+
94
97
/** Event emitted when the tab begins to animate towards the center as the active tab. */
95
98
@Output ( ) onCentering : EventEmitter < number > = new EventEmitter < number > ( ) ;
96
99
97
100
/** Event emitted when the tab completes its animation towards the center. */
98
101
@Output ( ) onCentered : EventEmitter < void > = new EventEmitter < void > ( true ) ;
99
102
100
103
/** The tab body content to display. */
101
- @Input ( 'content' ) _content : TemplatePortal < any > ;
104
+ @Input ( 'content' ) _contentPortal : TemplatePortal < any > ;
105
+
106
+ /** Scroll position of the tab before the user switched away. */
107
+ private _lastScrollPosition = 0 ;
102
108
103
109
/** The shifted index position of the tab body, where zero represents the active center tab. */
104
110
_position : MdTabBodyPositionState ;
@@ -146,7 +152,8 @@ export class MdTabBody implements OnInit, AfterViewChecked {
146
152
*/
147
153
ngAfterViewChecked ( ) {
148
154
if ( this . _isCenterPosition ( this . _position ) && ! this . _portalHost . hasAttached ( ) ) {
149
- this . _portalHost . attach ( this . _content ) ;
155
+ this . _portalHost . attach ( this . _contentPortal ) ;
156
+ this . _contentElement . nativeElement . scrollTop = this . _lastScrollPosition ;
150
157
}
151
158
}
152
159
@@ -159,6 +166,7 @@ export class MdTabBody implements OnInit, AfterViewChecked {
159
166
_onTranslateTabComplete ( e : AnimationEvent ) {
160
167
// If the end state is that the tab is not centered, then detach the content.
161
168
if ( ! this . _isCenterPosition ( e . toState ) && ! this . _isCenterPosition ( this . _position ) ) {
169
+ this . _lastScrollPosition = this . _contentElement . nativeElement . scrollTop || 0 ;
162
170
this . _portalHost . detach ( ) ;
163
171
}
164
172
@@ -176,7 +184,7 @@ export class MdTabBody implements OnInit, AfterViewChecked {
176
184
/** Whether the provided position state is considered center, regardless of origin. */
177
185
private _isCenterPosition ( position : MdTabBodyPositionState | string ) : boolean {
178
186
return position == 'center' ||
179
- position == 'left-origin-center' ||
180
- position == 'right-origin-center' ;
187
+ position == 'left-origin-center' ||
188
+ position == 'right-origin-center' ;
181
189
}
182
190
}
0 commit comments