Skip to content

Commit 759d85a

Browse files
crisbetommalerba
authored andcommitted
fix(material/tabs): pagination sometimes incorrectly shown after zoom (#23759)
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. (cherry picked from commit 8cdd3d7)
1 parent a24b1ac commit 759d85a

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
@@ -82,6 +82,7 @@ export class MatTabNav extends _MatTabNavBase implements AfterContentInit {
8282
@ContentChildren(forwardRef(() => MatTabLink), {descendants: true}) _items: QueryList<MatTabLink>;
8383
@ViewChild('tabListContainer', {static: true}) _tabListContainer: ElementRef;
8484
@ViewChild('tabList', {static: true}) _tabList: ElementRef;
85+
@ViewChild('tabListInner', {static: true}) _tabListInner: ElementRef;
8586
@ViewChild('nextPaginator') _nextPaginator: ElementRef<HTMLElement>;
8687
@ViewChild('previousPaginator') _previousPaginator: ElementRef<HTMLElement>;
8788
_inkBar: MatInkBar;

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

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

@@ -452,7 +453,7 @@ export abstract class MatPaginatedTabHeader
452453
labelBeforePos = offsetLeft;
453454
labelAfterPos = labelBeforePos + offsetWidth;
454455
} else {
455-
labelAfterPos = this._tabList.nativeElement.offsetWidth - offsetLeft;
456+
labelAfterPos = this._tabListInner.nativeElement.offsetWidth - offsetLeft;
456457
labelBeforePos = labelAfterPos - offsetWidth;
457458
}
458459

@@ -481,7 +482,7 @@ export abstract class MatPaginatedTabHeader
481482
this._showPaginationControls = false;
482483
} else {
483484
const isEnabled =
484-
this._tabList.nativeElement.scrollWidth > this._elementRef.nativeElement.offsetWidth;
485+
this._tabListInner.nativeElement.scrollWidth > this._elementRef.nativeElement.offsetWidth;
485486

486487
if (!isEnabled) {
487488
this.scrollDistance = 0;
@@ -523,7 +524,7 @@ export abstract class MatPaginatedTabHeader
523524
* should be called sparingly.
524525
*/
525526
_getMaxScrollDistance(): number {
526-
const lengthOfTabList = this._tabList.nativeElement.scrollWidth;
527+
const lengthOfTabList = this._tabListInner.nativeElement.scrollWidth;
527528
const viewLength = this._tabListContainer.nativeElement.offsetWidth;
528529
return lengthOfTabList - viewLength || 0;
529530
}

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
@@ -97,6 +97,7 @@ export class MatTabHeader extends _MatTabHeaderBase {
9797
@ViewChild(MatInkBar, {static: true}) _inkBar: MatInkBar;
9898
@ViewChild('tabListContainer', {static: true}) _tabListContainer: ElementRef;
9999
@ViewChild('tabList', {static: true}) _tabList: ElementRef;
100+
@ViewChild('tabListInner', {static: true}) _tabListInner: ElementRef;
100101
@ViewChild('nextPaginator') _nextPaginator: ElementRef<HTMLElement>;
101102
@ViewChild('previousPaginator') _previousPaginator: ElementRef<HTMLElement>;
102103

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
@@ -167,6 +167,7 @@ export class MatTabNav extends _MatTabNavBase {
167167
@ViewChild(MatInkBar, {static: true}) _inkBar: MatInkBar;
168168
@ViewChild('tabListContainer', {static: true}) _tabListContainer: ElementRef;
169169
@ViewChild('tabList', {static: true}) _tabList: ElementRef;
170+
@ViewChild('tabListInner', {static: true}) _tabListInner: ElementRef;
170171
@ViewChild('nextPaginator') _nextPaginator: ElementRef<HTMLElement>;
171172
@ViewChild('previousPaginator') _previousPaginator: ElementRef<HTMLElement>;
172173

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)