components icon indicating copy to clipboard operation
components copied to clipboard

Hammer.js overrides native drag&drop

Open taffeldt opened this issue 10 years ago • 12 comments

Bug, feature request, or proposal:

Probably a bug. Might be a proposal. Not entirely sure.

What is the expected behavior?

You should be able to use native HTML5 drag&drop, at least on non-Material elements.

What is the current behavior?

The dragstart event gets overriden by Hammer.js, so you can't access required event properties like dataTransfer.

What are the steps to reproduce?

With Hammer.js installed, bind the dragstart event to a function and try to access dataTransfer. It will be undefined. Alternatively uninstall Hammer.js and do the dame steps. You will get the error message: "Hammer.js is not loaded, can not bind dragstart event". For the first case I set up a plunker right here: http://plnkr.co/edit/CMzTNi0HKVxI9xI3ztsc?p=preview Make sure to check console output once you start dragging the first div.

What is the use-case or motivation for changing an existing behavior?

Angular Material 2 should not prevent you from using native APIs on other tags.

Which versions of Angular, Material, OS, browsers are affected?

Tested with Angular 2.0.1, Material 2.0.0-alpha.9-3 and Hammerjs 2.0.8 All browsers should be affected. Tested with Firefox 49.0.1 and Chrome 53.0.2785.143

Is there anything else we should know?

Overriding dragstart should not be necessary during Hammerjs initilisation. The drag event contains all necessary information. You can read the discussion on Reddit for additional information: https://www.reddit.com/r/Angular2/comments/56kh4g/html5_drag_drop/

taffeldt avatar Oct 09 '16 14:10 taffeldt

This is because the MdGestureConfig is registering the drag event in Angular's event manager.

It would be probably better to just have the slide event for now, because the drag event is not used by any component yet (only by the gestures demo)

devversion avatar Oct 09 '16 15:10 devversion

@DevVersion I think the drag event should be sufficient for gestures, if needed. dragstart and dragend* are required for HTML5 drag and drop and should not be overridden. MdGestureConfig#L11 should probably be modified to exclude them.

jimitndiaye avatar Oct 11 '16 10:10 jimitndiaye

I agree that we shouldn't be clobbering the native drag events.

jelbourn avatar Oct 11 '16 20:10 jelbourn

In the mean time, I found, you can add the following to app.module to revert to native drag events.

@Injectable()
export class AppGestureConfig extends HammerGestureConfig { }

@NgModule({
...
  providers: [{ provide: HAMMER_GESTURE_CONFIG, useClass: AppGestureConfig }],
...
})
export class AppModule {}

mina-skunk avatar Oct 18 '16 00:10 mina-skunk

#1025 is the same issue

ratscrew avatar Oct 19 '16 12:10 ratscrew

@jimitndiaye I did not mean to remove the drag events, I just said that we could use the slide recognizer, because it's based on the drag recognizer (just with a smaller threshold) and does not interfere with the native DOM events.

Anyways it seems that dragend and dragstart are now removed in #1458

Personally I would have removed all drag aliases for now, because those are not used by any component yet.

devversion avatar Oct 19 '16 15:10 devversion

Closed via #1458

jelbourn avatar Oct 27 '16 00:10 jelbourn

When this correction will be available ?

Sincerly

kgiroux avatar Nov 02 '16 11:11 kgiroux

@kgiroux in waiting for this change, I've manually updated the material.umd.js to remove the 2 events in conforming with the change that is pending as shown here merge

not ideal, but hopefully it helps if this is a blocker for you as it was for me.

mwamufiya avatar Nov 02 '16 12:11 mwamufiya

@mwamufiya, I follow the advice from @gatimus. But it is just a temporary fix. It is just for having a date of release. Thank for your quick reply =)

kgiroux avatar Nov 02 '16 13:11 kgiroux

Is this released ? Can we drag and drop rows in cdktables ?

rajjaiswalsaumya avatar Nov 14 '17 03:11 rajjaiswalsaumya

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.