Skip to content

fix(material-experimental/mdc-slider): remove pointerdown passive eve… #24766

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 4 commits into from
Apr 21, 2022
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
2 changes: 1 addition & 1 deletion src/e2e-app/mdc-slider/mdc-slider-e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {Component} from '@angular/core';
@Component({
selector: 'mdc-slider-e2e',
template: `
<mat-slider id="standard-slider">
<mat-slider id="standard-slider" discrete>
<input aria-label="Standard slider" matSliderThumb>
</mat-slider>

Expand Down
33 changes: 32 additions & 1 deletion src/material-experimental/mdc-slider/slider.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

import {clickElementAtPoint, getElement, Point} from '../../cdk/testing/private/e2e';
import {Thumb} from '@material/slider';
import {browser, by, element, ElementFinder} from 'protractor';
import {$, browser, by, element, ElementFinder} from 'protractor';
import {logging} from 'selenium-webdriver';

describe('MDC-based MatSlider', () => {
const getStandardSlider = () => element(by.id('standard-slider'));
Expand All @@ -32,6 +33,29 @@ describe('MDC-based MatSlider', () => {
await slideToValue(slider, 35, Thumb.END);
expect(await getSliderValue(slider, Thumb.END)).toBe(35);
});

it('should display the value indicator when focused', async () => {
await focusSliderThumb(slider, Thumb.END);
const rect: DOMRect = await browser.executeScript(
'return arguments[0].getBoundingClientRect();',
$('.mdc-slider__value-indicator'),
);

expect(rect.width).not.toBe(0);
expect(rect.height).not.toBe(0);

await browser.actions().mouseUp().perform();
});

it('should not cause passive event listener errors when changing the value', async () => {
// retrieving the logs clears the collection
await browser.manage().logs().get('browser');
await setValueByClick(slider, 15);

expect(await browser.manage().logs().get('browser')).not.toContain(
jasmine.objectContaining({level: logging.Level.SEVERE}),
);
});
});

describe('disabled slider', async () => {
Expand Down Expand Up @@ -96,6 +120,13 @@ async function getSliderValue(slider: ElementFinder, thumbPosition: Thumb): Prom
: Number(await inputs[0].getAttribute('value'));
}

/** Focuses on the MatSlider at the coordinates corresponding to the given thumb. */
async function focusSliderThumb(slider: ElementFinder, thumbPosition: Thumb): Promise<void> {
const webElement = await getElement(slider).getWebElement();
const coords = await getCoordsForValue(slider, await getSliderValue(slider, thumbPosition));
return await browser.actions().mouseMove(webElement, coords).mouseDown().perform();
}

/** Clicks on the MatSlider at the coordinates corresponding to the given value. */
async function setValueByClick(slider: ElementFinder, value: number): Promise<void> {
return clickElementAtPoint(slider, await getCoordsForValue(slider, value));
Expand Down
16 changes: 4 additions & 12 deletions src/material-experimental/mdc-slider/slider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -781,11 +781,7 @@ export class MatSlider
// would prefer to use "mousedown" as the default, for some reason it does not work (the
// callback is never triggered).
if (this._SUPPORTS_POINTER_EVENTS) {
this._elementRef.nativeElement.addEventListener(
'pointerdown',
this._layout,
passiveEventListenerOptions,
);
this._elementRef.nativeElement.addEventListener('pointerdown', this._layout);
} else {
this._elementRef.nativeElement.addEventListener('mouseenter', this._layout);
this._elementRef.nativeElement.addEventListener(
Expand All @@ -799,11 +795,7 @@ export class MatSlider
/** Removes the event listener that keeps sync the slider UI and the foundation in sync. */
_removeUISyncEventListener(): void {
if (this._SUPPORTS_POINTER_EVENTS) {
this._elementRef.nativeElement.removeEventListener(
'pointerdown',
this._layout,
passiveEventListenerOptions,
);
this._elementRef.nativeElement.removeEventListener('pointerdown', this._layout);
} else {
this._elementRef.nativeElement.removeEventListener('mouseenter', this._layout);
this._elementRef.nativeElement.removeEventListener(
Expand Down Expand Up @@ -1134,10 +1126,10 @@ class SliderAdapter implements MDCSliderAdapter {
getThumbKnobWidth = (thumbPosition: Thumb): number => {
return this._delegate._getKnobElement(thumbPosition).getBoundingClientRect().width;
};
getThumbBoundingClientRect = (thumbPosition: Thumb): ClientRect => {
getThumbBoundingClientRect = (thumbPosition: Thumb): DOMRect => {
return this._delegate._getThumbElement(thumbPosition).getBoundingClientRect();
};
getBoundingClientRect = (): ClientRect => {
getBoundingClientRect = (): DOMRect => {
return this._delegate._elementRef.nativeElement.getBoundingClientRect();
};
getValueIndicatorContainerWidth = (thumbPosition: Thumb): number => {
Expand Down