@@ -13,7 +13,8 @@ import {
1313 QueryList ,
1414 ViewChild ,
1515 ViewChildren ,
16- OnDestroy
16+ OnDestroy ,
17+ NgZone
1718} from '@angular/core' ;
1819import { Subscription } from 'rxjs' ;
1920import { IgxBadgeModule } from '../badge/badge.component' ;
@@ -23,6 +24,7 @@ import { IgxTabItemComponent } from './tab-item.component';
2324import { IgxTabsGroupComponent } from './tabs-group.component' ;
2425import { IgxLeftButtonStyleDirective , IgxRightButtonStyleDirective , IgxTabItemTemplateDirective } from './tabs.directives' ;
2526import { IgxTabsBase , IgxTabItemBase } from './tabs.common' ;
27+ import ResizeObserver from 'resize-observer-polyfill' ;
2628
2729export enum TabsType {
2830 FIXED = 'fixed' ,
@@ -228,6 +230,7 @@ export class IgxTabsComponent implements IgxTabsBase, AfterViewInit, OnDestroy {
228230
229231 private _groupChanges$ : Subscription ;
230232 private _selectedIndex = - 1 ;
233+ private _resizeObserver : ResizeObserver ;
231234
232235 /**
233236 * @hidden
@@ -295,7 +298,7 @@ export class IgxTabsComponent implements IgxTabsBase, AfterViewInit, OnDestroy {
295298 }
296299 }
297300
298- constructor ( private _element : ElementRef ) {
301+ constructor ( private _element : ElementRef , private _ngZone : NgZone ) {
299302 }
300303
301304 /**
@@ -326,6 +329,17 @@ export class IgxTabsComponent implements IgxTabsBase, AfterViewInit, OnDestroy {
326329 this . _groupChanges$ = this . groups . changes . subscribe ( ( ) => {
327330 this . resetSelectionOnCollectionChanged ( ) ;
328331 } ) ;
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+ } ) ;
329343 }
330344
331345 /**
@@ -335,6 +349,10 @@ export class IgxTabsComponent implements IgxTabsBase, AfterViewInit, OnDestroy {
335349 if ( this . _groupChanges$ ) {
336350 this . _groupChanges$ . unsubscribe ( ) ;
337351 }
352+
353+ this . _ngZone . runOutsideAngular ( ( ) => {
354+ this . _resizeObserver . disconnect ( ) ;
355+ } ) ;
338356 }
339357
340358 private resetSelectionOnCollectionChanged ( ) : void {
@@ -445,16 +463,17 @@ export class IgxTabsComponent implements IgxTabsBase, AfterViewInit, OnDestroy {
445463 // animation for the new panel/group (not needed for tab only mode)
446464 public transformContentAnimation ( tab : IgxTabItemBase , duration : number ) : void {
447465 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' ;
449467 this . contentsContainer . nativeElement . style . transform = `translate(${ - contentOffset } px)` ;
450468 }
451469
452470 /**
453471 * @hidden
454472 */
455- public transformIndicatorAnimation ( element : HTMLElement ) : void {
473+ public transformIndicatorAnimation ( element : HTMLElement , duration = 0.3 ) : void {
456474 if ( this . selectedIndicator ) {
457475 this . selectedIndicator . nativeElement . style . visibility = 'visible' ;
476+ this . selectedIndicator . nativeElement . style . transitionDuration = duration > 0 ? `${ duration } s` : 'initial' ;
458477 this . selectedIndicator . nativeElement . style . width = `${ element . offsetWidth } px` ;
459478 this . selectedIndicator . nativeElement . style . transform = `translate(${ element . offsetLeft } px)` ;
460479 }
0 commit comments