Skip to content

Commit a8dd126

Browse files
committed
fix(material/tabs): pagination sometimes incorrectly shown after zoom
Currently if one of the end tabs is selected and the user zooms in, we may end up showing the pagination unnecessarily. The issue comes from the fact that there's a transition on the ink bar which can cause the parent overflow while it is being measured. These changes resolve the issue by measuring a different element. Fixes #23724.
1 parent c7e0f99 commit a8dd126

File tree

10 files changed

+16
-7
lines changed

10 files changed

+16
-7
lines changed

src/material-experimental/mdc-tabs/tab-header.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
class="mat-mdc-tab-list"
2222
role="tablist"
2323
(cdkObserveContent)="_onContentChanges()">
24-
<div class="mat-mdc-tab-labels">
24+
<div class="mat-mdc-tab-labels" #tabListInner>
2525
<ng-content></ng-content>
2626
</div>
2727
</div>

src/material-experimental/mdc-tabs/tab-header.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export class MatTabHeader extends _MatTabHeaderBase implements AfterContentInit
5454
@ContentChildren(MatTabLabelWrapper, {descendants: false}) _items: QueryList<MatTabLabelWrapper>;
5555
@ViewChild('tabListContainer', {static: true}) _tabListContainer: ElementRef;
5656
@ViewChild('tabList', {static: true}) _tabList: ElementRef;
57+
@ViewChild('tabListInner', {static: true}) _tabListInner: ElementRef;
5758
@ViewChild('nextPaginator') _nextPaginator: ElementRef<HTMLElement>;
5859
@ViewChild('previousPaginator') _previousPaginator: ElementRef<HTMLElement>;
5960
_inkBar: MatInkBar;

src/material-experimental/mdc-tabs/tab-nav-bar/tab-nav-bar.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
<div class="mat-mdc-tab-link-container" #tabListContainer (keydown)="_handleKeydown($event)">
1414
<div class="mat-mdc-tab-list" #tabList (cdkObserveContent)="_onContentChanges()">
15-
<div class="mat-mdc-tab-links">
15+
<div class="mat-mdc-tab-links" #tabListInner>
1616
<ng-content></ng-content>
1717
</div>
1818
</div>

src/material-experimental/mdc-tabs/tab-nav-bar/tab-nav-bar.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export class MatTabNav extends _MatTabNavBase implements AfterContentInit {
7979
@ContentChildren(forwardRef(() => MatTabLink), {descendants: true}) _items: QueryList<MatTabLink>;
8080
@ViewChild('tabListContainer', {static: true}) _tabListContainer: ElementRef;
8181
@ViewChild('tabList', {static: true}) _tabList: ElementRef;
82+
@ViewChild('tabListInner', {static: true}) _tabListInner: ElementRef;
8283
@ViewChild('nextPaginator') _nextPaginator: ElementRef<HTMLElement>;
8384
@ViewChild('previousPaginator') _previousPaginator: ElementRef<HTMLElement>;
8485
_inkBar: MatInkBar;

src/material/tabs/paginated-tab-header.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export abstract class MatPaginatedTabHeader implements AfterContentChecked, Afte
7575
abstract _inkBar: {hide: () => void, alignToElement: (element: HTMLElement) => void};
7676
abstract _tabListContainer: ElementRef<HTMLElement>;
7777
abstract _tabList: ElementRef<HTMLElement>;
78+
abstract _tabListInner: ElementRef<HTMLElement>;
7879
abstract _nextPaginator: ElementRef<HTMLElement>;
7980
abstract _previousPaginator: ElementRef<HTMLElement>;
8081

@@ -442,7 +443,7 @@ export abstract class MatPaginatedTabHeader implements AfterContentChecked, Afte
442443
labelBeforePos = offsetLeft;
443444
labelAfterPos = labelBeforePos + offsetWidth;
444445
} else {
445-
labelAfterPos = this._tabList.nativeElement.offsetWidth - offsetLeft;
446+
labelAfterPos = this._tabListInner.nativeElement.offsetWidth - offsetLeft;
446447
labelBeforePos = labelAfterPos - offsetWidth;
447448
}
448449

@@ -471,7 +472,7 @@ export abstract class MatPaginatedTabHeader implements AfterContentChecked, Afte
471472
this._showPaginationControls = false;
472473
} else {
473474
const isEnabled =
474-
this._tabList.nativeElement.scrollWidth > this._elementRef.nativeElement.offsetWidth;
475+
this._tabListInner.nativeElement.scrollWidth > this._elementRef.nativeElement.offsetWidth;
475476

476477
if (!isEnabled) {
477478
this.scrollDistance = 0;
@@ -513,7 +514,7 @@ export abstract class MatPaginatedTabHeader implements AfterContentChecked, Afte
513514
* should be called sparingly.
514515
*/
515516
_getMaxScrollDistance(): number {
516-
const lengthOfTabList = this._tabList.nativeElement.scrollWidth;
517+
const lengthOfTabList = this._tabListInner.nativeElement.scrollWidth;
517518
const viewLength = this._tabListContainer.nativeElement.offsetWidth;
518519
return (lengthOfTabList - viewLength) || 0;
519520
}

src/material/tabs/tab-header.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
[class._mat-animation-noopable]="_animationMode === 'NoopAnimations'"
1717
role="tablist"
1818
(cdkObserveContent)="_onContentChanges()">
19-
<div class="mat-tab-labels">
19+
<div class="mat-tab-labels" #tabListInner>
2020
<ng-content></ng-content>
2121
</div>
2222
<mat-ink-bar></mat-ink-bar>

src/material/tabs/tab-header.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ export class MatTabHeader extends _MatTabHeaderBase {
9090
@ViewChild(MatInkBar, {static: true}) _inkBar: MatInkBar;
9191
@ViewChild('tabListContainer', {static: true}) _tabListContainer: ElementRef;
9292
@ViewChild('tabList', {static: true}) _tabList: ElementRef;
93+
@ViewChild('tabListInner', {static: true}) _tabListInner: ElementRef;
9394
@ViewChild('nextPaginator') _nextPaginator: ElementRef<HTMLElement>;
9495
@ViewChild('previousPaginator') _previousPaginator: ElementRef<HTMLElement>;
9596

src/material/tabs/tab-nav-bar/tab-nav-bar.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
[class._mat-animation-noopable]="_animationMode === 'NoopAnimations'"
1616
#tabList
1717
(cdkObserveContent)="_onContentChanges()">
18-
<div class="mat-tab-links">
18+
<div class="mat-tab-links" #tabListInner>
1919
<ng-content></ng-content>
2020
</div>
2121
<mat-ink-bar></mat-ink-bar>

src/material/tabs/tab-nav-bar/tab-nav-bar.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ export class MatTabNav extends _MatTabNavBase {
158158
@ViewChild(MatInkBar, {static: true}) _inkBar: MatInkBar;
159159
@ViewChild('tabListContainer', {static: true}) _tabListContainer: ElementRef;
160160
@ViewChild('tabList', {static: true}) _tabList: ElementRef;
161+
@ViewChild('tabListInner', {static: true}) _tabListInner: ElementRef;
161162
@ViewChild('nextPaginator') _nextPaginator: ElementRef<HTMLElement>;
162163
@ViewChild('previousPaginator') _previousPaginator: ElementRef<HTMLElement>;
163164

tools/public_api_guard/material/tabs.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,8 @@ export class MatTabHeader extends _MatTabHeaderBase {
296296
// (undocumented)
297297
_tabListContainer: ElementRef;
298298
// (undocumented)
299+
_tabListInner: ElementRef;
300+
// (undocumented)
299301
static ɵcmp: i0.ɵɵComponentDeclaration<MatTabHeader, "mat-tab-header", never, { "selectedIndex": "selectedIndex"; }, { "selectFocusedIndex": "selectFocusedIndex"; "indexFocused": "indexFocused"; }, ["_items"], ["*"]>;
300302
// (undocumented)
301303
static ɵfac: i0.ɵɵFactoryDeclaration<MatTabHeader, [null, null, null, { optional: true; }, null, null, { optional: true; }]>;
@@ -406,6 +408,8 @@ export class MatTabNav extends _MatTabNavBase {
406408
// (undocumented)
407409
_tabListContainer: ElementRef;
408410
// (undocumented)
411+
_tabListInner: ElementRef;
412+
// (undocumented)
409413
static ɵcmp: i0.ɵɵComponentDeclaration<MatTabNav, "[mat-tab-nav-bar]", ["matTabNavBar", "matTabNav"], { "color": "color"; }, {}, ["_items"], ["*"]>;
410414
// (undocumented)
411415
static ɵfac: i0.ɵɵFactoryDeclaration<MatTabNav, [null, { optional: true; }, null, null, null, null, { optional: true; }]>;

0 commit comments

Comments
 (0)