From 8ae8ceed818de67fc8e0d47dacddf985e6e71caf Mon Sep 17 00:00:00 2001 From: Aliullov Vlad <91639107+GoodDayForSurf@users.noreply.github.com> Date: Thu, 2 Nov 2023 14:51:08 +0400 Subject: [PATCH] Add pointerEventStrategy option to GlobalConfig for setting EventStrategy (#25901) --- packages/devextreme/js/common.d.ts | 1 + packages/devextreme/js/events/pointer.js | 20 +++++++++++++++++-- .../pointerParts/strategySelectionTests.js | 10 ++++++++++ packages/devextreme/ts/dx.all.d.ts | 1 + 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/packages/devextreme/js/common.d.ts b/packages/devextreme/js/common.d.ts index af3238725b86..2f9ed396f157 100644 --- a/packages/devextreme/js/common.d.ts +++ b/packages/devextreme/js/common.d.ts @@ -344,6 +344,7 @@ export type GlobalConfig = { * @public */ oDataFilterToLower?: boolean; + pointerEventStrategy?: 'mouse-and-touch' | 'mouse' | 'touch'; /** * @docid * @default false diff --git a/packages/devextreme/js/events/pointer.js b/packages/devextreme/js/events/pointer.js index 445f2a512a71..e6839c01cf18 100644 --- a/packages/devextreme/js/events/pointer.js +++ b/packages/devextreme/js/events/pointer.js @@ -1,3 +1,4 @@ +import GlobalConfig from '../core/config'; import * as support from '../core/utils/support'; import { each } from '../core/utils/iterator'; import devices from '../core/devices'; @@ -63,8 +64,13 @@ import MouseAndTouchStrategy from './pointer/mouse_and_touch'; * @module events/pointer */ -const getStrategy = (support, device) => { - const { tablet, phone } = device; +const getStrategy = (support, { tablet, phone }) => { + const pointerEventStrategy = getStrategyFromGlobalConfig(); + + if(pointerEventStrategy) { + return pointerEventStrategy; + } + if(support.touch && !(tablet || phone)) { return MouseAndTouchStrategy; } @@ -93,6 +99,16 @@ const pointer = { out: 'dxpointerout' }; +function getStrategyFromGlobalConfig() { + const eventStrategyName = GlobalConfig().pointerEventStrategy; + + return { + 'mouse-and-touch': MouseAndTouchStrategy, + 'touch': TouchStrategy, + 'mouse': MouseStrategy, + }[eventStrategyName]; +} + ///#DEBUG pointer.getStrategy = getStrategy; diff --git a/packages/devextreme/testing/tests/DevExpress.ui.events/pointerParts/strategySelectionTests.js b/packages/devextreme/testing/tests/DevExpress.ui.events/pointerParts/strategySelectionTests.js index 316854ab5538..20c35dbfa8d8 100644 --- a/packages/devextreme/testing/tests/DevExpress.ui.events/pointerParts/strategySelectionTests.js +++ b/packages/devextreme/testing/tests/DevExpress.ui.events/pointerParts/strategySelectionTests.js @@ -1,3 +1,4 @@ +import GlobalConfig from 'core/config'; import { getStrategy } from 'events/pointer'; import TouchStrategy from 'events/pointer/touch'; import MouseStrategy from 'events/pointer/mouse'; @@ -6,6 +7,15 @@ import MouseAndTouchStrategy from 'events/pointer/mouse_and_touch'; const { test } = QUnit; QUnit.module('Strategy selection', () => { + test('Use strategy from GlobalConfig', function(assert) { + GlobalConfig({ pointerEventStrategy: 'mouse-and-touch' }); + + const strategy = getStrategy({}, {}, {}); + + assert.strictEqual(strategy, MouseAndTouchStrategy); + GlobalConfig({ pointerEventStrategy: null }); + }); + test('Use the Mouse strategy by default', function(assert) { const strategy = getStrategy({}, {}, {}); diff --git a/packages/devextreme/ts/dx.all.d.ts b/packages/devextreme/ts/dx.all.d.ts index ac7fd3904b44..b9ef79c1cb34 100644 --- a/packages/devextreme/ts/dx.all.d.ts +++ b/packages/devextreme/ts/dx.all.d.ts @@ -1507,6 +1507,7 @@ declare module DevExpress.common { * [descr:GlobalConfig.oDataFilterToLower] */ oDataFilterToLower?: boolean; + pointerEventStrategy?: 'mouse-and-touch' | 'mouse' | 'touch'; /** * [descr:GlobalConfig.rtlEnabled] */