material icon indicating copy to clipboard operation
material copied to clipboard

Clicks not reliably firing on child element of a parent registered via MdGesture on mobile (iOS)

Open jjf1 opened this issue 11 years ago • 3 comments

In 0.10.1 (and since 0.9.4), on desktop clicks fire perfectly for md-button inside md-bottom-sheet, but on mobile, specifically iOS (Android not yet tested), the clicks frequently do not fire.

Here are 3 such button-icon elements, inside md-bottom-sheet.

    <md-bottom-sheet>
     <md-toolbar>
      <div class="md-toolbar-tools" layout="row" layout-align="space-between center">
        <md-button class="md-icon-button" ng-click="prev($event)" aria-label="prev">
          <md-icon md-svg-icon="navigation:chevron_left"></md-icon>
        </md-button>
        <md-button class="md-icon-button" ng-click="next($event)" aria-label="next">
          <md-icon md-svg-icon="navigation:chevron_right"></md-icon>
        </md-button>
        <md-button class="md-icon-button close-button" ng-click="close($event)" aria-label="close">
          <md-icon md-svg-icon="content:clear"></md-icon>
        </md-button>   
      </div>
     </md-toolbar>
     .
     .
     .
    </md-bottom-sheet>

Debugging led to AngularMaterial's MdGesture system in core.js,

    angular
     .module('material.core.gestures', [ ])
     .provider('$mdGesture', MdGestureProvider)
     .factory('$$MdGestureHandler', MdGestureHandler)
     .run( attachToDocument );
  • Inside attachToDocument() gesture event listeners are bound to the DOM document object. The listeners send the event (be it mouse, touch or pointer) to all handlers registered via MdGestureHandler...
    angular.element(document)
      .on(START_EVENTS, gestureStart)
      .on(MOVE_EVENTS, gestureMove)
      .on(END_EVENTS, gestureEnd));

This works great for material components that have explicitly registered for a specific event (such as md-bottom-sheet, which is registered for drag), however it also presents challenges for child elements that are not registered (md-button and md-icon). Debugging the button clicks revealed:

  • All inadvertent touchmove events between the touchstart and touchend (finger moves left, right, up or down while attempting a tap), are, by design, broadcast to all registered handlers.
  • But when one of those handlers consumes the touchmove (e.g. calls ev.stopPropagation()), the click never fires.

One workaround is to intercept the touchmove on the unregistered element in the App code, before it otherwise gets dispatched by the MdGesture system...

    angular.module('myApp', [ ])
     .run( function() {
        $(document).on('touchmove', 'md-icon', function(evt) { 
          evt.stopPropagation();
        });
      });

The MdGesture system may also be related to this issue/workaround https://github.com/angular/material/issues/2073 (md-bottom-sheet does not allow scrolling [on mobile]).

jjf1 avatar Aug 15 '15 03:08 jjf1

I have made a Codepen using 0.10.1 and HEAD which reproduces this issue:

  • 0.10.1 - https://codepen.io/topherfangio/pen/adovjG?editors=001
  • HEAD - https://codepen.io/topherfangio/pen/YwKymo?editors=001

As best as I can tell, the issue arises when the button is tapped multiple times in quick succession. It seems that if you tap and wait until the animation finishes before your next tap, everything works fine.

We will continue to investigate.

topherfangio avatar Dec 01 '15 19:12 topherfangio

@jjf1 Can you please review to see if the above Codepens reproduce the issue you originally reported? If not, could you fork the HEAD version to show exactly what is happening?

topherfangio avatar Dec 01 '15 19:12 topherfangio

@topherfangio Apologies for delay. Tyvm for setting this up. Will investigate codepen in a couple of days.

jjf1 avatar Jan 22 '16 16:01 jjf1