Skip to content

Commit 9c0c789

Browse files
gkalpaknetman92
authored andcommitted
test(browerTrigger): ensure touch events initialize correctly on touch enabled Chrome
On certain browsers (e.g. on desktop Chrome with touch-events enabled), using the `initTouchEvent()` method (introduced in 06a9f0a) did not correctly initialize the event, nor did the event get dispatched on the target element. Using the `Event` constructor and manually attaching a `TouchList`, works around the issue (although not a proper fix). Fixes angular#11471 Closes angular#11493
1 parent 40453d2 commit 9c0c789

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/ngScenario/browserTrigger.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -134,17 +134,15 @@
134134
}
135135

136136
function createTouchEvent(element, eventType, x, y) {
137-
var evnt = document.createEvent('TouchEvent');
137+
var evnt = new Event(eventType);
138138
x = x || 0;
139139
y = y || 0;
140140

141141
var touch = document.createTouch(window, element, Date.now(), x, y, x, y);
142142
var touches = document.createTouchList(touch);
143-
var targetTouches = document.createTouchList(touch);
144-
var changedTouches = document.createTouchList(touch);
145143

146-
evnt.initTouchEvent(eventType, true, true, window, null, 0, 0, 0, 0, false, false, false, false,
147-
touches, targetTouches, changedTouches, 1, 0);
144+
evnt.touches = touches;
145+
148146
return evnt;
149147
}
150148
}());

0 commit comments

Comments
 (0)