@@ -19,6 +19,7 @@ import {
1919 OnDestroy ,
2020 Directive ,
2121 Inject ,
22+ Input ,
2223} from '@angular/core' ;
2324import { Direction , Directionality } from '@angular/cdk/bidi' ;
2425import { coerceNumberProperty } from '@angular/cdk/coercion' ;
@@ -116,6 +117,13 @@ export abstract class MatPaginatedTabHeader implements AfterContentChecked, Afte
116117 /** Stream that will stop the automated scrolling. */
117118 private _stopScrolling = new Subject < void > ( ) ;
118119
120+ /**
121+ * Whether pagination should be disabled. This can be used to avoid unnecessary
122+ * layout recalculations if it's known that pagination won't be required.
123+ */
124+ @Input ( )
125+ disablePagination : boolean = false ;
126+
119127 /** The index of the active tab. */
120128 get selectedIndex ( ) : number { return this . _selectedIndex ; }
121129 set selectedIndex ( value : number ) {
@@ -364,6 +372,10 @@ export abstract class MatPaginatedTabHeader implements AfterContentChecked, Afte
364372
365373 /** Performs the CSS transformation on the tab list that will cause the list to scroll. */
366374 _updateTabScrollPosition ( ) {
375+ if ( this . disablePagination ) {
376+ return ;
377+ }
378+
367379 const scrollDistance = this . scrollDistance ;
368380 const platform = this . _platform ;
369381 const translateX = this . _getLayoutDirection ( ) === 'ltr' ? - scrollDistance : scrollDistance ;
@@ -422,9 +434,15 @@ export abstract class MatPaginatedTabHeader implements AfterContentChecked, Afte
422434 * should be called sparingly.
423435 */
424436 _scrollToLabel ( labelIndex : number ) {
437+ if ( this . disablePagination ) {
438+ return ;
439+ }
440+
425441 const selectedLabel = this . _items ? this . _items . toArray ( ) [ labelIndex ] : null ;
426442
427- if ( ! selectedLabel ) { return ; }
443+ if ( ! selectedLabel ) {
444+ return ;
445+ }
428446
429447 // The view length is the visible width of the tab labels.
430448 const viewLength = this . _tabListContainer . nativeElement . offsetWidth ;
@@ -460,18 +478,22 @@ export abstract class MatPaginatedTabHeader implements AfterContentChecked, Afte
460478 * should be called sparingly.
461479 */
462480 _checkPaginationEnabled ( ) {
463- const isEnabled =
464- this . _tabList . nativeElement . scrollWidth > this . _elementRef . nativeElement . offsetWidth ;
481+ if ( this . disablePagination ) {
482+ this . _showPaginationControls = false ;
483+ } else {
484+ const isEnabled =
485+ this . _tabList . nativeElement . scrollWidth > this . _elementRef . nativeElement . offsetWidth ;
465486
466- if ( ! isEnabled ) {
467- this . scrollDistance = 0 ;
468- }
487+ if ( ! isEnabled ) {
488+ this . scrollDistance = 0 ;
489+ }
469490
470- if ( isEnabled !== this . _showPaginationControls ) {
471- this . _changeDetectorRef . markForCheck ( ) ;
472- }
491+ if ( isEnabled !== this . _showPaginationControls ) {
492+ this . _changeDetectorRef . markForCheck ( ) ;
493+ }
473494
474- this . _showPaginationControls = isEnabled ;
495+ this . _showPaginationControls = isEnabled ;
496+ }
475497 }
476498
477499 /**
@@ -484,10 +506,14 @@ export abstract class MatPaginatedTabHeader implements AfterContentChecked, Afte
484506 * should be called sparingly.
485507 */
486508 _checkScrollingControls ( ) {
487- // Check if the pagination arrows should be activated.
488- this . _disableScrollBefore = this . scrollDistance == 0 ;
489- this . _disableScrollAfter = this . scrollDistance == this . _getMaxScrollDistance ( ) ;
490- this . _changeDetectorRef . markForCheck ( ) ;
509+ if ( this . disablePagination ) {
510+ this . _disableScrollAfter = this . _disableScrollBefore = true ;
511+ } else {
512+ // Check if the pagination arrows should be activated.
513+ this . _disableScrollBefore = this . scrollDistance == 0 ;
514+ this . _disableScrollAfter = this . scrollDistance == this . _getMaxScrollDistance ( ) ;
515+ this . _changeDetectorRef . markForCheck ( ) ;
516+ }
491517 }
492518
493519 /**
@@ -550,6 +576,10 @@ export abstract class MatPaginatedTabHeader implements AfterContentChecked, Afte
550576 * @returns Information on the current scroll distance and the maximum.
551577 */
552578 private _scrollTo ( position : number ) {
579+ if ( this . disablePagination ) {
580+ return { maxScrollDistance : 0 , distance : 0 } ;
581+ }
582+
553583 const maxScrollDistance = this . _getMaxScrollDistance ( ) ;
554584 this . _scrollDistance = Math . max ( 0 , Math . min ( maxScrollDistance , position ) ) ;
555585
0 commit comments