Problem/Motivation

When adding a link to a webform dialog the dialog modal is not working on a touch device. Instead of opening the modal, it follows the link.

Steps to reproduce

Create a link like the following:
<a href="/en/form/testform?source_entity_type=ENTITY_TYPE&amp;source_entity_id=ENTITY_ID" class="webform-dialog" data-dialog-options="{&quot;width&quot;:800}">Open Webform Dialog</a>
and click on it - it should open a dialog like on desktop-devices, but it follows the link on touch-devices. This is also happening in the inspector with touch-simulation enabled.

Proposed resolution

Add touchstart event in webform.dialog.js @ line 83. Change from click to touchstart click

Issue fork webform-3427966

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

roromedia created an issue. See original summary.

roromedia’s picture

Issue summary: View changes
roromedia’s picture

Issue summary: View changes
roromedia’s picture

Issue summary: View changes

jrockowitz made their first commit to this issue’s fork.

jrockowitz’s picture

Status: Active » Needs review

jrockowitz’s picture

Status: Needs review » Fixed

  • jrockowitz committed 9752e1bf on 6.2.x
    Issue #3427966: Webform Dialog Modal triggered with a link doesn't work...
jrockowitz’s picture

Version: 6.2.2 » 6.2.x-dev

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

anybody’s picture

Sorry, but I have to disagree this was a good idea. Touch events are special, yes, but at least it should at least have been touchend instead of touchstart.
Using touchend ensures the event fires when the user lifts their finger, reducing accidental triggers.

Still, I think it should not be needed at all in modern browsers, according to this answer: https://stackoverflow.com/a/11398089/10031165

Should we reopen this or create a follow-up?

Which browser and device did you use @roromedia?

thomas.frobieter’s picture

Maybe @roromedia could provide the affected browser? If I remind corretly, this where a Safari bug, not sure if click is still problematic in iOS Safari.

roromedia’s picture

The bug occurred on iOS (when tested I used the latest stable version and versions below as well) iPads with Safari as standard browser.

thomas.frobieter’s picture

Title: Webform Dialog Modal triggered with a link doesn't work on touch device » Webform Dialog Modal triggered with a link doesn't work on iOS Safari

Thanks @roromedia.

So I changed the task title accordingly.

Just came across this problematic behaviour again on Android. Extremely annoying when simple scrolling triggers the webform dialog.

We should try if a simple cursor: pointer; solves the problem with the click event on Safari, see:
https://stackoverflow.com/questions/24077725/mobile-safari-sometimes-doe...

EDIT: Or use the new 'pointerup' event instead.

thomas.frobieter’s picture

I've tested with 'pointerup' instead 'click touchstart' and it seems to work well on all devices and browsers.

But someone should try this on a real Iphone, I only have the simulator.

So should we re-open this issue or create a new one?

anybody’s picture

@jrockowitz could you reopen this one to fix it? Or would you prefer a follow-up?

anruether’s picture

@thomas.frobieter On an Iphone SE2 18.3.2, Safari:

  • 'pointerup' does not trigger the modal but opens the link
  • 'touchend click' does open the modal when the finger is lifted, which does not really improve the situation much

I'll attach a patch that reverts this issues patch, because we rather use a link for some safari users, instead of interfering with everybody's scrolling.

edit: @roromedia So your issue is only with ipads? Because I can't reproduce it on my iphone. It would be good then to get more info on how widespread the faulty behavior is, so we don't repair something for a few, but introduce regressions for a lot.

thomas.frobieter’s picture

@thomas.frobieter On an Iphone SE2 18.3.2, Safari:

'pointerup' does not trigger the modal but opens the link
'touchend click' does open the modal when the finger is lifted, which does not really improve the situation much

That's strange. Safari 13.1/13.2 should support pointerup. I think we should debug this, as the pointer event sounds like the cleanest solution to me.

Here is a Pen to test the events: https://codepen.io/thomas-frobieter/pen/qEdNoEr

I can confirm that the link opens after the pointerup event is fired. For reasons, preventDefault() is not working. I will do further research on this.

EDIT: Okay, when using 'pointerup' you also need to register 'click' and add preventDefault() for both.

thomas.frobieter’s picture

Can someone with an Apple touch device please test the 'pointerup click' button? => https://codepen.io/thomas-frobieter/full/qEdNoEr

I have tried on the iOS Simulator and it seems to work well.

If the real device test also works well, I will create a follow up issue.

liam morland’s picture

This has caused #3506020: When scrolling, the modal window opens automatically. Please review the fix in that issue.

anybody’s picture

@liam morland: There's nothing to review yet. We should either fix both issues over at #3506020: When scrolling, the modal window opens automatically or here. They are very closely related, nearly the same and surely have the same fix. As this one is closed, maybe better move over?

So ==> Further work here: https://www.drupal.org/project/webform/issues/3506020 <==

liam morland’s picture

Yes, please work in the other issue. There isn't a patch, but there is a prose description of the change in comment 4.