#1717·shepherd

Touch scroll not possible on highlighted area

Author: freakzlikeCreated Dec 8, 2021Updated Oct 9, 2024

It is not possible to scroll with touch on the highlighted area or on the modal. However touch scroll on the grayed area and mouse scroll is possible.

Reproduce

This can be tested on shepherdjs.dev:

  1. Open shepherdjs.dev on small mobile device or with dev-tools
  2. Click through the first two steps till you reach the 02. Example section
  3. Try to touch scroll on the code snippet on the example (should not work)
  4. Try to touch scroll on the 01. How to include code snippet (should work)
  5. Try to scroll with mouse wheel (should work)

The default behavior of the touchmove event has been disabled here: https://github.com/shipshapecode/shepherd/blob/99d4f995f79d6bf99ea55c2bd0c62f309f2de968/src/js/components/shepherd-modal.svelte#L90-L92 https://github.com/shipshapecode/shepherd/blob/99d4f995f79d6bf99ea55c2bd0c62f309f2de968/src/js/components/shepherd-modal.svelte#L98-L107

Workaround

I'm currently using this workaround to avoid the call of preventDefault

javascript
const allowTouchmove = (event) => {
  event.stopPropagation()
}

const tour = new Shepherd.Tour({
  defaultStepOptions: {
    when: {
      show () {
        const target = this.getTarget()
        if (target) {
          target.addEventListener('touchmove', allowTouchmove)
        }
      },
      hide () {
        const target = this.getTarget()
        if (target) {
          target.removeEventListener('touchmove', allowTouchmove)
        }
      }
    }
  }
})

Suggestion

IMO the preventDefault of the touchmove event should be at least avoidable through the step configuration (something like allowTouchScroll: true). Also the behavior between mouse scroll, touch scroll on grayed area and touch scroll on highlighted area feels inconsistent and not understandable for a user.