From 1c91c975f268bb4b094fdd4642c8d034cc65c297 Mon Sep 17 00:00:00 2001 From: helenxywu Date: Tue, 9 Mar 2021 15:23:41 -0800 Subject: [PATCH] Global setting to use click on tap handlers Tap used to be recommended handler. However this changed to click in recent years, and tap actually causes problems with touch/scrolling. Global setting to always just use click. --- lib/mixins/gesture-event-listeners.js | 9 +++++++++ lib/utils/settings.js | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/lib/mixins/gesture-event-listeners.js b/lib/mixins/gesture-event-listeners.js index 71a4577ff7..3711fded2c 100644 --- a/lib/mixins/gesture-event-listeners.js +++ b/lib/mixins/gesture-event-listeners.js @@ -11,6 +11,7 @@ import '../utils/boot.js'; import { dedupingMixin } from '../utils/mixin.js'; import { addListener, removeListener } from '../utils/gestures.js'; +import { useClickOnTap } from '../utils/settings.js'; /** * Element class mixin that provides API for adding Polymer's cross-platform @@ -46,6 +47,10 @@ export const GestureEventListeners = dedupingMixin((superClass) => { * @override */ _addEventListenerToNode(node, eventName, handler) { + if (useClickOnTap && eventName === 'tap') { + super._addEventListenerToNode(node, 'click', handler); + return; + } if (!addListener(node, eventName, handler)) { super._addEventListenerToNode(node, eventName, handler); } @@ -61,6 +66,10 @@ export const GestureEventListeners = dedupingMixin((superClass) => { * @override */ _removeEventListenerFromNode(node, eventName, handler) { + if (useClickOnTap && eventName === 'tap') { + super._removeEventListenerFromNode(node, 'click', handler); + return; + } if (!removeListener(node, eventName, handler)) { super._removeEventListenerFromNode(node, eventName, handler); } diff --git a/lib/utils/settings.js b/lib/utils/settings.js index ee70d3c14b..c10209748b 100644 --- a/lib/utils/settings.js +++ b/lib/utils/settings.js @@ -98,6 +98,14 @@ export const getSanitizeDOMValue = function() { export let passiveTouchGestures = window.Polymer && window.Polymer.setPassiveTouchGestures || false; +/** + * Globally settable property to make on-tap use on-click. + * Defaults to `false` for backwards compatibility. + */ +export const useClickOnTap = + window.Polymer && window.Polymer.useClickOnTap || false; + + /** * Sets `passiveTouchGestures` globally for all elements using Polymer Gestures. *