Skip to content

Commit 824dd84

Browse files
committed
fix(material/tabs): update MatTab _scrollToLabel function to always display a label from its start (#26736)
1 parent 5ea4ca5 commit 824dd84

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,6 @@ const passiveEventListenerOptions = normalizePassiveListenerOptions({
5757
*/
5858
export type ScrollDirection = 'after' | 'before';
5959

60-
/**
61-
* The distance in pixels that will be overshot when scrolling a tab label into view. This helps
62-
* provide a small affordance to the label next to it.
63-
*/
64-
const EXAGGERATED_OVERSCROLL = 60;
65-
6660
/**
6761
* Amount of milliseconds to wait before starting to scroll the header automatically.
6862
* Set a little conservatively in order to handle fake events dispatched on touch devices.
@@ -524,10 +518,13 @@ export abstract class MatPaginatedTabHeader
524518

525519
if (labelBeforePos < beforeVisiblePos) {
526520
// Scroll header to move label to the before direction
527-
this.scrollDistance -= beforeVisiblePos - labelBeforePos + EXAGGERATED_OVERSCROLL;
521+
this.scrollDistance -= beforeVisiblePos - labelBeforePos;
528522
} else if (labelAfterPos > afterVisiblePos) {
529523
// Scroll header to move label to the after direction
530-
this.scrollDistance += labelAfterPos - afterVisiblePos + EXAGGERATED_OVERSCROLL;
524+
this.scrollDistance += Math.min(
525+
labelAfterPos - afterVisiblePos,
526+
labelBeforePos - beforeVisiblePos,
527+
);
531528
}
532529
}
533530

0 commit comments

Comments
 (0)