Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit deb3dfc

Browse files
committed
fix(gesture): 'drag' gestures don't clean up touch action styles on parent
Fixes #11147
1 parent 5b0c9ba commit deb3dfc

File tree

4 files changed

+40
-20
lines changed

4 files changed

+40
-20
lines changed

src/components/bottomSheet/bottom-sheet.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ function MdBottomSheetDirective($mdBottomSheet) {
168168
*
169169
* @description
170170
* Hide the existing bottom sheet and resolve the promise returned from
171-
* `$mdBottomSheet.show()`. This call will close the most recently opened/current bottomsheet (if
171+
* `$mdBottomSheet.show()`. This call will close the most recently opened/current bottom sheet (if
172172
* any).
173173
*
174174
* <em><b>Note:</b> Use a `.then()` on your `.show()` to handle this callback.</em>
@@ -303,6 +303,10 @@ function MdBottomSheetProvider($$interimElementProvider) {
303303

304304
/**
305305
* Adds the drag gestures to the bottom sheet.
306+
* @param {angular.JQLite} element where CSS transitions will be applied
307+
* @param {angular.JQLite} parent used for registering gesture listeners
308+
* @return {Function} function that removes gesture listeners that were set up by
309+
* registerGestures()
306310
*/
307311
function registerGestures(element, parent) {
308312
var deregister = $mdGesture.register(parent, 'drag', { horizontal: false });

src/core/services/gesture/gesture.js

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ MdGestureProvider.prototype = {
115115
* @ngInject
116116
*/
117117
function MdGesture($$MdGestureHandler, $$rAF, $timeout, $mdUtil) {
118-
var touchActionProperty = getTouchAction();
118+
var touchActionProperty = $mdUtil.getTouchAction();
119119
var hasJQuery = (typeof window.jQuery !== 'undefined') && (angular.element === window.jQuery);
120120

121121
var self = {
@@ -276,16 +276,26 @@ function MdGesture($$MdGestureHandler, $$rAF, $timeout, $mdUtil) {
276276
horizontal: true,
277277
cancelMultiplier: 1.5
278278
},
279+
/**
280+
* @param {angular.JQLite} element where touch action styles need to be adjusted
281+
* @param {{horizontal: boolean}=} options object whose horizontal property can specify to
282+
* apply 'pan-y' or 'pan-x' touch actions.
283+
*/
279284
onSetup: function(element, options) {
280285
if (touchActionProperty) {
281286
// We check for horizontal to be false, because otherwise we would overwrite the default opts.
282287
this.oldTouchAction = element[0].style[touchActionProperty];
283288
element[0].style[touchActionProperty] = options.horizontal ? 'pan-y' : 'pan-x';
284289
}
285290
},
291+
/**
292+
* @param {angular.JQLite} element where styles need to be cleaned up
293+
*/
286294
onCleanup: function(element) {
287295
if (this.oldTouchAction) {
288296
element[0].style[touchActionProperty] = this.oldTouchAction;
297+
} else {
298+
element[0].style[touchActionProperty] = null;
289299
}
290300
},
291301
onStart: function (ev) {
@@ -362,20 +372,6 @@ function MdGesture($$MdGestureHandler, $$rAF, $timeout, $mdUtil) {
362372
}
363373
}
364374
});
365-
366-
function getTouchAction() {
367-
var testEl = document.createElement('div');
368-
var vendorPrefixes = ['', 'webkit', 'Moz', 'MS', 'ms', 'o'];
369-
370-
for (var i = 0; i < vendorPrefixes.length; i++) {
371-
var prefix = vendorPrefixes[i];
372-
var property = prefix ? prefix + 'TouchAction' : 'touchAction';
373-
if (angular.isDefined(testEl.style[property])) {
374-
return property;
375-
}
376-
}
377-
}
378-
379375
}
380376

381377
/**

src/core/services/gesture/gesture.spec.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,17 +364,18 @@ describe('$mdGesture', function() {
364364

365365
describe('drag', function() {
366366

367-
var startDragSpy, el, dragSpy, endDragSpy, doc;
367+
var startDragSpy, el, dragSpy, endDragSpy, doc, deRegisterEvents, touchAction;
368368

369369
beforeEach(function() {
370-
inject(function($mdGesture, $document) {
370+
inject(function($mdGesture, $document, $mdUtil) {
371371
doc = $document;
372372
startDragSpy = jasmine.createSpy('dragstart');
373373
dragSpy = jasmine.createSpy('drag');
374374
endDragSpy = jasmine.createSpy('dragend');
375375
el = angular.element('<div>');
376376

377-
$mdGesture.register(el, 'drag');
377+
touchAction = $mdUtil.getTouchAction();
378+
deRegisterEvents = $mdGesture.register(el, 'drag');
378379
el.on('$md.dragstart', startDragSpy)
379380
.on('$md.drag' , dragSpy)
380381
.on('$md.dragend' , endDragSpy);
@@ -448,6 +449,12 @@ describe('$mdGesture', function() {
448449
});
449450
}));
450451

452+
453+
it('should clean up styles when de-registered', inject(function($mdGesture, $document) {
454+
deRegisterEvents();
455+
// Ensure that no 'pan-x' or 'pan-y' values are left behind.
456+
expect(el[0].style[touchAction]).toBe('');
457+
}));
451458
});
452459

453460
describe('swipe', function() {

src/core/util/util.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,20 @@ function UtilFactory($document, $timeout, $compile, $rootScope, $$mdAnimate, $in
965965
* documentMode is an IE-only property
966966
* http://msdn.microsoft.com/en-us/library/ie/cc196988(v=vs.85).aspx
967967
*/
968-
msie: window.document.documentMode
968+
msie: window.document.documentMode,
969+
970+
getTouchAction: function() {
971+
var testEl = document.createElement('div');
972+
var vendorPrefixes = ['', 'webkit', 'Moz', 'MS', 'ms', 'o'];
973+
974+
for (var i = 0; i < vendorPrefixes.length; i++) {
975+
var prefix = vendorPrefixes[i];
976+
var property = prefix ? prefix + 'TouchAction' : 'touchAction';
977+
if (angular.isDefined(testEl.style[property])) {
978+
return property;
979+
}
980+
}
981+
}
969982
};
970983

971984
// Instantiate other namespace utility methods

0 commit comments

Comments
 (0)