@@ -13,7 +13,8 @@ import {
13
13
QueryList ,
14
14
ViewChild ,
15
15
ViewChildren ,
16
- OnDestroy
16
+ OnDestroy ,
17
+ NgZone
17
18
} from '@angular/core' ;
18
19
import { Subscription } from 'rxjs' ;
19
20
import { IgxBadgeModule } from '../badge/badge.component' ;
@@ -23,6 +24,7 @@ import { IgxTabItemComponent } from './tab-item.component';
23
24
import { IgxTabsGroupComponent } from './tabs-group.component' ;
24
25
import { IgxLeftButtonStyleDirective , IgxRightButtonStyleDirective , IgxTabItemTemplateDirective } from './tabs.directives' ;
25
26
import { IgxTabsBase , IgxTabItemBase } from './tabs.common' ;
27
+ import ResizeObserver from 'resize-observer-polyfill' ;
26
28
27
29
export enum TabsType {
28
30
FIXED = 'fixed' ,
@@ -228,6 +230,7 @@ export class IgxTabsComponent implements IgxTabsBase, AfterViewInit, OnDestroy {
228
230
229
231
private _groupChanges$ : Subscription ;
230
232
private _selectedIndex = - 1 ;
233
+ private _resizeObserver : ResizeObserver ;
231
234
232
235
/**
233
236
* @hidden
@@ -295,7 +298,7 @@ export class IgxTabsComponent implements IgxTabsBase, AfterViewInit, OnDestroy {
295
298
}
296
299
}
297
300
298
- constructor ( private _element : ElementRef ) {
301
+ constructor ( private _element : ElementRef , private _ngZone : NgZone ) {
299
302
}
300
303
301
304
/**
@@ -326,6 +329,17 @@ export class IgxTabsComponent implements IgxTabsBase, AfterViewInit, OnDestroy {
326
329
this . _groupChanges$ = this . groups . changes . subscribe ( ( ) => {
327
330
this . resetSelectionOnCollectionChanged ( ) ;
328
331
} ) ;
332
+
333
+ this . _ngZone . runOutsideAngular ( ( ) => {
334
+ this . _resizeObserver = new ResizeObserver ( ( ) => {
335
+ if ( ! this . hasContentTabs && this . _selectedIndex >= 0 && this . _selectedIndex < this . tabs . length ) {
336
+ const newTab = this . tabs . toArray ( ) [ this . _selectedIndex ] ;
337
+ this . transformContentAnimation ( newTab , 0 ) ;
338
+ }
339
+ } ) ;
340
+
341
+ this . _resizeObserver . observe ( this . tabsContainer . nativeElement ) ;
342
+ } ) ;
329
343
}
330
344
331
345
/**
@@ -335,6 +349,10 @@ export class IgxTabsComponent implements IgxTabsBase, AfterViewInit, OnDestroy {
335
349
if ( this . _groupChanges$ ) {
336
350
this . _groupChanges$ . unsubscribe ( ) ;
337
351
}
352
+
353
+ this . _ngZone . runOutsideAngular ( ( ) => {
354
+ this . _resizeObserver . disconnect ( ) ;
355
+ } ) ;
338
356
}
339
357
340
358
private resetSelectionOnCollectionChanged ( ) : void {
@@ -445,16 +463,17 @@ export class IgxTabsComponent implements IgxTabsBase, AfterViewInit, OnDestroy {
445
463
// animation for the new panel/group (not needed for tab only mode)
446
464
public transformContentAnimation ( tab : IgxTabItemBase , duration : number ) : void {
447
465
const contentOffset = this . tabsContainer . nativeElement . offsetWidth * tab . index ;
448
- this . contentsContainer . nativeElement . style . transitionDuration = `${ duration } s` ;
466
+ this . contentsContainer . nativeElement . style . transitionDuration = duration > 0 ? `${ duration } s` : 'initial' ;
449
467
this . contentsContainer . nativeElement . style . transform = `translate(${ - contentOffset } px)` ;
450
468
}
451
469
452
470
/**
453
471
* @hidden
454
472
*/
455
- public transformIndicatorAnimation ( element : HTMLElement ) : void {
473
+ public transformIndicatorAnimation ( element : HTMLElement , duration = 0.3 ) : void {
456
474
if ( this . selectedIndicator ) {
457
475
this . selectedIndicator . nativeElement . style . visibility = 'visible' ;
476
+ this . selectedIndicator . nativeElement . style . transitionDuration = duration > 0 ? `${ duration } s` : 'initial' ;
458
477
this . selectedIndicator . nativeElement . style . width = `${ element . offsetWidth } px` ;
459
478
this . selectedIndicator . nativeElement . style . transform = `translate(${ element . offsetLeft } px)` ;
460
479
}
0 commit comments