Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: stop ontouchstart events on overlay #302

Merged
merged 3 commits into from
Dec 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/js/utils/cleanup.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defer } from 'lodash';
import { classNames as modalClassNames } from './modal';
import { classNames as modalClassNames, preventModalBodyTouch } from './modal';
import { getElementForStep } from './dom';

/**
Expand Down Expand Up @@ -45,6 +45,7 @@ export function cleanupStepEventListeners() {
if (typeof this._onScreenChange === 'function') {
window.removeEventListener('resize', this._onScreenChange, false);
window.removeEventListener('scroll', this._onScreenChange, false);
window.removeEventListener('touchmove', preventModalBodyTouch, false);

this._onScreenChange = null;
}
Expand Down
9 changes: 9 additions & 0 deletions src/js/utils/dom.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { preventModalBodyTouch, preventModalOverlayTouch } from './modal';

/**
* Helper method to check if element is hidden, since we cannot use :visible without jQuery
* @param {HTMLElement} element The element to check for visibility
Expand Down Expand Up @@ -78,6 +80,13 @@ function addStepEventListeners() {

window.addEventListener('resize', this._onScreenChange, false);
window.addEventListener('scroll', this._onScreenChange, false);

const overlay = document.querySelector('#shepherdModalOverlayContainer');
// Prevents window from moving on touch.
window.addEventListener('touchmove', preventModalBodyTouch, false);

// Allows content to move on touch.
overlay.addEventListener('touchmove', preventModalOverlayTouch, false);
}

/**
Expand Down
10 changes: 10 additions & 0 deletions src/js/utils/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@ function getModalMaskOpening(modalElement) {
return modalElement.querySelector(`#${elementIds.modalOverlayMaskOpening}`);
}

function preventModalBodyTouch(event) {
event.preventDefault();
}

function preventModalOverlayTouch(event) {
event.stopPropagation();
}

/**
* Remove any leftover modal target classes and add the modal target class to the currentElement
* @param {HTMLElement} currentElement The element for the current step
Expand All @@ -154,6 +162,8 @@ function toggleShepherdModalClass(currentElement) {
export {
createModalOverlay,
positionModalOpening,
preventModalBodyTouch,
preventModalOverlayTouch,
closeModalOpening,
getModalMaskOpening,
elementIds,
Expand Down