Shadow DOM: touchmove not working on mobile #1060
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I tried to use noUiSlider in a Stencil web component using the ShadowDOM (
shadow: true
) and noticed that the slider handle can't be dragged on mobile. If I disable the ShadowDOM in my web component, everything works fine.I traced this back to the function
isTouchOnTarget
that always returnsfalse
when it's called in the scope ofe.type === "touchmove"
.(Touch) events in the ShadowDOM are redirected to their host element. You can observe that
checktouch.Target
is the host element whileeventTarget
is thehandle div
within the shadow root of the component. Of course, thediv
does not contain the host element but it's actually the other way around. To check this, you have to callcontains
on theshadowRoot
element in the host.I'm not sure if there is a better approach to fix this but dragging on mobile does work now even in a shadowed web component.