Skip to content

fix(tabs): don't start auto-scroll when right clicking on buttons #18033

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

Merged
merged 1 commit into from
Jan 22, 2020
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions src/material-experimental/mdc-tabs/tab-header.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[matRippleDisabled]="_disableScrollBefore || disableRipple"
[class.mat-mdc-tab-header-pagination-disabled]="_disableScrollBefore"
(click)="_handlePaginatorClick('before')"
(mousedown)="_handlePaginatorPress('before')"
(mousedown)="_handlePaginatorPress('before', $event)"
(touchend)="_stopInterval()">
<div class="mat-mdc-tab-header-pagination-chevron"></div>
</div>
Expand All @@ -31,7 +31,7 @@
mat-ripple
[matRippleDisabled]="_disableScrollAfter || disableRipple"
[class.mat-mdc-tab-header-pagination-disabled]="_disableScrollAfter"
(mousedown)="_handlePaginatorPress('after')"
(mousedown)="_handlePaginatorPress('after', $event)"
(click)="_handlePaginatorClick('after')"
(touchend)="_stopInterval()">
<div class="mat-mdc-tab-header-pagination-chevron"></div>
Expand Down
11 changes: 11 additions & 0 deletions src/material-experimental/mdc-tabs/tab-header.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
dispatchKeyboardEvent,
createKeyboardEvent,
dispatchEvent,
createMouseEvent,
} from '@angular/cdk/testing/private';
import {CommonModule} from '@angular/common';
import {Component, ViewChild} from '@angular/core';
Expand Down Expand Up @@ -458,6 +459,16 @@ describe('MDC-based MatTabHeader', () => {
expect(header.scrollDistance).toBe(previousDistance);
}));

it('should not scroll when pressing the right mouse button', fakeAsync(() => {
expect(header.scrollDistance).toBe(0, 'Expected to start off not scrolled.');

dispatchEvent(nextButton, createMouseEvent('mousedown', undefined, undefined, 2));
fixture.detectChanges();
tick(3000);

expect(header.scrollDistance).toBe(0, 'Expected not to have scrolled after a while.');
}));

/**
* Asserts that auto scrolling using the next button works.
* @param startEventName Name of the event that is supposed to start the scrolling.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
mat-ripple [matRippleDisabled]="_disableScrollBefore || disableRipple"
[class.mat-mdc-tab-header-pagination-disabled]="_disableScrollBefore"
(click)="_handlePaginatorClick('before')"
(mousedown)="_handlePaginatorPress('before')"
(mousedown)="_handlePaginatorPress('before', $event)"
(touchend)="_stopInterval()">
<div class="mat-mdc-tab-header-pagination-chevron"></div>
</div>
Expand All @@ -24,7 +24,7 @@
aria-hidden="true"
mat-ripple [matRippleDisabled]="_disableScrollAfter || disableRipple"
[class.mat-mdc-tab-header-pagination-disabled]="_disableScrollAfter"
(mousedown)="_handlePaginatorPress('after')"
(mousedown)="_handlePaginatorPress('after', $event)"
(click)="_handlePaginatorClick('after')"
(touchend)="_stopInterval()">
<div class="mat-mdc-tab-header-pagination-chevron"></div>
Expand Down
8 changes: 7 additions & 1 deletion src/material/tabs/paginated-tab-header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,13 @@ export abstract class MatPaginatedTabHeader implements AfterContentChecked, Afte
* Starts scrolling the header after a certain amount of time.
* @param direction In which direction the paginator should be scrolled.
*/
_handlePaginatorPress(direction: ScrollDirection) {
_handlePaginatorPress(direction: ScrollDirection, mouseEvent?: MouseEvent) {
// Don't start auto scrolling for right mouse button clicks. Note that we shouldn't have to
// null check the `button`, but we do it so we don't break tests that use fake events.
if (mouseEvent && mouseEvent.button != null && mouseEvent.button !== 0) {
return;
}

// Avoid overlapping timers.
this._stopInterval();

Expand Down
4 changes: 2 additions & 2 deletions src/material/tabs/tab-header.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
mat-ripple [matRippleDisabled]="_disableScrollBefore || disableRipple"
[class.mat-tab-header-pagination-disabled]="_disableScrollBefore"
(click)="_handlePaginatorClick('before')"
(mousedown)="_handlePaginatorPress('before')"
(mousedown)="_handlePaginatorPress('before', $event)"
(touchend)="_stopInterval()">
<div class="mat-tab-header-pagination-chevron"></div>
</div>
Expand All @@ -28,7 +28,7 @@
aria-hidden="true"
mat-ripple [matRippleDisabled]="_disableScrollAfter || disableRipple"
[class.mat-tab-header-pagination-disabled]="_disableScrollAfter"
(mousedown)="_handlePaginatorPress('after')"
(mousedown)="_handlePaginatorPress('after', $event)"
(click)="_handlePaginatorClick('after')"
(touchend)="_stopInterval()">
<div class="mat-tab-header-pagination-chevron"></div>
Expand Down
11 changes: 11 additions & 0 deletions src/material/tabs/tab-header.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
dispatchKeyboardEvent,
createKeyboardEvent,
dispatchEvent,
createMouseEvent,
} from '@angular/cdk/testing/private';
import {CommonModule} from '@angular/common';
import {Component, ViewChild} from '@angular/core';
Expand Down Expand Up @@ -458,6 +459,16 @@ describe('MatTabHeader', () => {
expect(header.scrollDistance).toBe(previousDistance);
}));

it('should not scroll when pressing the right mouse button', fakeAsync(() => {
expect(header.scrollDistance).toBe(0, 'Expected to start off not scrolled.');

dispatchEvent(nextButton, createMouseEvent('mousedown', undefined, undefined, 2));
fixture.detectChanges();
tick(3000);

expect(header.scrollDistance).toBe(0, 'Expected not to have scrolled after a while.');
}));

/**
* Asserts that auto scrolling using the next button works.
* @param startEventName Name of the event that is supposed to start the scrolling.
Expand Down
4 changes: 2 additions & 2 deletions src/material/tabs/tab-nav-bar/tab-nav-bar.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
mat-ripple [matRippleDisabled]="_disableScrollBefore || disableRipple"
[class.mat-tab-header-pagination-disabled]="_disableScrollBefore"
(click)="_handlePaginatorClick('before')"
(mousedown)="_handlePaginatorPress('before')"
(mousedown)="_handlePaginatorPress('before', $event)"
(touchend)="_stopInterval()">
<div class="mat-tab-header-pagination-chevron"></div>
</div>
Expand All @@ -23,7 +23,7 @@
aria-hidden="true"
mat-ripple [matRippleDisabled]="_disableScrollAfter || disableRipple"
[class.mat-tab-header-pagination-disabled]="_disableScrollAfter"
(mousedown)="_handlePaginatorPress('after')"
(mousedown)="_handlePaginatorPress('after', $event)"
(click)="_handlePaginatorClick('after')"
(touchend)="_stopInterval()">
<div class="mat-tab-header-pagination-chevron"></div>
Expand Down