Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(material/tabs): avoid pagination infinite loop in safari #29121

Merged
merged 1 commit into from
May 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/material/tabs/paginated-tab-header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -550,18 +550,27 @@ export abstract class MatPaginatedTabHeader
if (this.disablePagination) {
this._showPaginationControls = false;
} else {
const isEnabled =
this._tabListInner.nativeElement.scrollWidth > this._elementRef.nativeElement.offsetWidth;
const scrollWidth = this._tabListInner.nativeElement.scrollWidth;
const containerWidth = this._elementRef.nativeElement.offsetWidth;

// Usually checking that the scroll width is greater than the container width should be
// enough, but on Safari at specific widths the browser ends up rounding up when there's
// no pagination and rounding down once the pagination is added. This can throw the component
// into an infinite loop where the pagination shows up and disappears constantly. We work
// around it by adding a threshold to the calculation. From manual testing the threshold
// can be lowered to 2px and still resolve the issue, but we set a higher one to be safe.
// This shouldn't cause any content to be clipped, because tabs have a 24px horizontal
// padding. See b/316395154 for more information.
const isEnabled = scrollWidth - containerWidth >= 5;

if (!isEnabled) {
this.scrollDistance = 0;
}

if (isEnabled !== this._showPaginationControls) {
this._showPaginationControls = isEnabled;
this._changeDetectorRef.markForCheck();
}

this._showPaginationControls = isEnabled;
}
}

Expand Down
Loading