From 59869b9d49c1ad8bf14c9fb37918323b950c225b Mon Sep 17 00:00:00 2001 From: Darius Oleskevicius Date: Wed, 6 Jun 2018 03:32:38 +1000 Subject: [PATCH] fix(slider): suppress console warnings in Chrome for Android when scrubbing (#5219) Instead of calling preventDefault() on touchstart in Chrome, set touch-action: none style on progress control to prevent unintended scrolling. Fixes #4650. --- src/css/components/_progress.scss | 1 + src/js/slider/slider.js | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/css/components/_progress.scss b/src/css/components/_progress.scss index b4b876e07..e56d10058 100644 --- a/src/css/components/_progress.scss +++ b/src/css/components/_progress.scss @@ -6,6 +6,7 @@ @include flex(auto); @include display-flex(center); min-width: 4em; + touch-action: none; } .video-js .vjs-progress-control.disabled { diff --git a/src/js/slider/slider.js b/src/js/slider/slider.js index 35743104d..9a16c365d 100644 --- a/src/js/slider/slider.js +++ b/src/js/slider/slider.js @@ -4,6 +4,7 @@ import Component from '../component.js'; import * as Dom from '../utils/dom.js'; import {assign} from '../utils/obj'; +import {IS_CHROME} from '../utils/browser.js'; /** * The base functionality for a slider. Can be vertical or horizontal. @@ -145,7 +146,16 @@ class Slider extends Component { handleMouseDown(event) { const doc = this.bar.el_.ownerDocument; - event.preventDefault(); + if (event.type === 'mousedown') { + event.preventDefault(); + } + // Do not call preventDefault() on touchstart in Chrome + // to avoid console warnings. Use a 'touch-action: none' style + // instead to prevent unintented scrolling. + // https://developers.google.com/web/updates/2017/01/scrolling-intervention + if (event.type === 'touchstart' && !IS_CHROME) { + event.preventDefault(); + } Dom.blockTextSelection(); this.addClass('vjs-sliding');