bootstrap icon indicating copy to clipboard operation
bootstrap copied to clipboard

$modal + ngTouch input issues on iOS/Android

Open ijlind opened this issue 12 years ago • 25 comments

There is a weird issue with modal windows containing input fields on iOS and Android if ngTouch is used. For some reason, you can only focus on an input field with a long touch gesture. A regular touch gesture won't focus on the field (and thus won't open the virtual keyboard). On desktop browsers the issue does not exist but it also seems to work as it should on Mobile IE (WP8).

Here's a plunkr demonstrating the issue: http://plnkr.co/edit/X95ZBUd6FK2I2R14e3Lr?p=preview

ijlind avatar May 30 '14 11:05 ijlind

+1 Why has this not been released. It is clearly a serious pain for everyone

twhamilton avatar Jul 23 '15 15:07 twhamilton

I had this issue but it took me an embarassingly long time to realise I had it. The directive approach did fix this issue for me though since I use ngTouch in other parts of my UI. I suppose another approach would be divide the portions using ngTouch into a seperate module and just have that module depend on ngTouch. That might mean ngTouch won't interfere with modals.

A PR solution could look like the directive provided though really the angularjs team should fix this one. The issue is scheduled to be fixed in either angularjs 1.4.x or 1.5.x so we might have to wait a while for them.

Fixing it ourselves here would help other people having the problem and not knowing about it or who can't wait on a new version of angularjs.

sean-stanley avatar Jul 23 '15 19:07 sean-stanley

This issue also affects selects on modals (see plunker http://plnkr.co/edit/2phDw62EVl1z9egd8EkA?p=preview) @jdhiro's fix https://github.com/angular-ui/bootstrap/issues/2017#issuecomment-39515923 gets around this issue too.

Having the modal in a separate module doesn't get around this issue unfortunately.

ximon avatar Aug 20 '15 15:08 ximon

:+1:

entrity avatar Aug 26 '15 16:08 entrity

The following fixed the issue for me. My best guess is that the clicks are continuing to propagate, and eventually result in the modal getting focus, but I have not confirmed that hypothesis:

(function() {
  angular.module('someModule')
    .directive('input', [
      function() {
        return {
          restrict: 'E',
          link: link
        };
      }
    ]);

  angular.module('someModule')
    .directive('textarea', [
      function() {
        return {
          restrict: 'E',
          link: link
        };
      }
    ]);

  function link(scope, elem) {
    // bind the events iff this is an input/textarea within a modal
    if (elem.parents('.modal').length) {
      elem.on('touchstart', function(e) {
        elem.focus();
        e.preventDefault();
        e.stopPropagation();
      });
    }
  }
})();

I did not test whether both preventDefault and stopPropagation were necessary, as I assume I'll remove these directives when it's patched in ngTouch / angular / angular-ui-bootstrap :)

rbalicki2 avatar Aug 27 '15 14:08 rbalicki2