Skip to content

Commit

Permalink
fix(slider): mobile sliding regression
Browse files Browse the repository at this point in the history
fixes #5894

Forgot to disable touch-action in the previous change. When dragging the slider, the browser believes it is instead a scroll or touchmove rather than an intended pointermove. `touch-action: none` disables this.

PiperOrigin-RevId: 310629089
  • Loading branch information
Elliott Marquez authored and copybara-github committed May 8, 2020
1 parent 2f052d8 commit e844443
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/mdc-slider/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@
.mdc-slider {
@include color-accessible(secondary, $query: $query);

&--disable-touch-action {
@include feature-targeting-mixins.targets($feat-structure) {
touch-action: none;
}
}

&--disabled {
$disabled-color: #9a9a9a;

Expand Down
1 change: 1 addition & 0 deletions packages/mdc-slider/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const cssClasses = {
HAS_TRACK_MARKER: 'mdc-slider--display-markers',
IN_TRANSIT: 'mdc-slider--in-transit',
IS_DISCRETE: 'mdc-slider--discrete',
DISABLE_TOUCH_ACTION: 'mdc-slider--disable-touch-action',
};

const strings = {
Expand Down
10 changes: 10 additions & 0 deletions packages/mdc-slider/foundation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,16 @@ export class MDCSliderFoundation extends MDCFoundation<MDCSliderAdapter> {
evtName, this.thumbContainerPointerHandler_);
});

if (hasPointerEventSupport) {
/*
* When pointermove happens, if too much sliding happens, the browser
* believes you are panning in the x direction and stops firing
* pointermove events and supplies its own gestures. (similar to
* preventing default on touchmove)
*/
this.adapter_.addClass(cssClasses.DISABLE_TOUCH_ACTION);
}

this.adapter_.registerInteractionHandler('keydown', this.keydownHandler_);
this.adapter_.registerInteractionHandler('focus', this.focusHandler_);
this.adapter_.registerInteractionHandler('blur', this.blurHandler_);
Expand Down
17 changes: 17 additions & 0 deletions packages/mdc-slider/test/foundation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,23 @@ describe('MDCSliderFoundation', () => {
.toHaveBeenCalledWith(isA(Function));
});

it('#init disables touch action if pointerevents are supported', () => {
const {foundation, mockAdapter} = setupTest();

mockAdapter.computeBoundingRect.and.returnValue({width: 0, left: 0});
foundation.init();

const hasPointer = !!window.PointerEvent;

if (hasPointer) {
expect(mockAdapter.addClass)
.toHaveBeenCalledWith(cssClasses.DISABLE_TOUCH_ACTION);
} else {
expect(mockAdapter.addClass)
.not.toHaveBeenCalledWith(cssClasses.DISABLE_TOUCH_ACTION);
}
});

it('#init checks if slider is discrete and if display track markers', () => {
const {foundation, mockAdapter} = setupTest();

Expand Down

0 comments on commit e844443

Please sign in to comment.