Skip to content

Commit 1004531

Browse files
committed
fix(material/tabs): avoid interrupting click event when scrolling the header
When a header is scrollable, we scroll a tab into view whenever it receives focus. The problem is that if focus is moved as a result of a mouse/touch event, the tab can be moved out from under the pointer, interrupting the click. These changes work around the issue by not scrolling the header on mouse/touch focus. Fixes #21898.
1 parent aa7dc00 commit 1004531

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/material/tabs/tab-group.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,11 @@ export abstract class _MatTabGroupBase extends _MatTabGroupMixinBase implements
376376

377377
/** Callback for when the focused state of a tab has changed. */
378378
_tabFocusChanged(focusOrigin: FocusOrigin, index: number) {
379-
if (focusOrigin) {
379+
// Mouse/touch focus happens during the `mousedown`/`touchstart` phase which
380+
// can cause the tab to be moved out from under the pointer, interrupting the
381+
// click sequence (see #21898). We don't need to scroll the tab into view for
382+
// such cases anyway, because it will be done when the tab becomes selected.
383+
if (focusOrigin && focusOrigin !== 'mouse' && focusOrigin !== 'touch') {
380384
this._tabHeader.focusIndex = index;
381385
}
382386
}

0 commit comments

Comments
 (0)