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 (#25901)
  • Loading branch information
GoodDayForSurf authored Nov 2, 2023
1 parent beedd6e commit 8ae8cee
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/devextreme/js/common.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ export type GlobalConfig = {
* @public
*/
oDataFilterToLower?: boolean;
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
1 change: 1 addition & 0 deletions packages/devextreme/ts/dx.all.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1507,6 +1507,7 @@ declare module DevExpress.common {
* [descr:GlobalConfig.oDataFilterToLower]
*/
oDataFilterToLower?: boolean;
pointerEventStrategy?: 'mouse-and-touch' | 'mouse' | 'touch';
/**
* [descr:GlobalConfig.rtlEnabled]
*/
Expand Down

0 comments on commit 8ae8cee

Please sign in to comment.