Skip to content

Commit

Permalink
Add pointerEventStrategy option to GlobalConfig for setting EventStra…
Browse files Browse the repository at this point in the history
…tegy (#26060)

Co-authored-by: Mikhail Preyskurantov <[email protected]>
  • Loading branch information
GoodDayForSurf and mpreyskurantov authored Nov 20, 2023
1 parent 85c0174 commit 66fe85c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
4 changes: 4 additions & 0 deletions packages/devextreme/js/common.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,10 @@ export type GlobalConfig = {
* @public
*/
oDataFilterToLower?: boolean;
/**
* @deprecated Attention! This field is not documented and should only be specified in a limited number of use cases. For more information, please submit a ticket to our Support Center.
*/
pointerEventStrategy?: 'mouse-and-touch' | 'mouse' | 'touch';
/**
* @docid
* @default false
Expand Down
20 changes: 18 additions & 2 deletions packages/devextreme/js/events/pointer.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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({}, {}, {});

Expand Down
4 changes: 4 additions & 0 deletions packages/devextreme/ts/dx.all.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1506,6 +1506,10 @@ declare module DevExpress.common {
* [descr:GlobalConfig.oDataFilterToLower]
*/
oDataFilterToLower?: boolean;
/**
* @deprecated Attention! This field is not documented and should only be specified in a limited number of use cases. For more information, please submit a ticket to our Support Center.
*/
pointerEventStrategy?: 'mouse-and-touch' | 'mouse' | 'touch';
/**
* [descr:GlobalConfig.rtlEnabled]
*/
Expand Down

0 comments on commit 66fe85c

Please sign in to comment.