Skip to content

Commit 4279ff1

Browse files
authored
fix(material/tabs): avoid interrupting click event when scrolling the header (#21911)
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 0742bab commit 4279ff1

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
@@ -407,7 +407,11 @@ export abstract class _MatTabGroupBase extends _MatTabGroupMixinBase implements
407407

408408
/** Callback for when the focused state of a tab has changed. */
409409
_tabFocusChanged(focusOrigin: FocusOrigin, index: number) {
410-
if (focusOrigin) {
410+
// Mouse/touch focus happens during the `mousedown`/`touchstart` phase which
411+
// can cause the tab to be moved out from under the pointer, interrupting the
412+
// click sequence (see #21898). We don't need to scroll the tab into view for
413+
// such cases anyway, because it will be done when the tab becomes selected.
414+
if (focusOrigin && focusOrigin !== 'mouse' && focusOrigin !== 'touch') {
411415
this._tabHeader.focusIndex = index;
412416
}
413417
}

0 commit comments

Comments
 (0)