Skip to content

Commit f32a73f

Browse files
committed
H5 Safari fix delay when dropping
fix for #1541 * on Safari we had a delay due to a 300ms+ animating back to old location on drop. 'dragend' wasn't called (what we use) until that animation was done. to fix that had to call `preventDefault()` during drag https://stackoverflow.com/questions/61760755/how-to-fire-dragend-event-immediately * for that to work I ALSO had to remove `{passive: true}` when adding the drag event, so passing just 'true' for grabing event NOTE: I noticed Safari doesn't auto-scroll the grid (didn't before), but chrome Mac does. html5 drag event is painfully incompatible between browsers...
1 parent aaa167c commit f32a73f

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

doc/CHANGES.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ Change log
4646
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
4747
## 3.1.3-dev
4848

49-
- fix [1557](https://github.com/gridstack/gridstack.js/pull/1557) fixed no-drop cursor on windows when dragging within a default grid (no external drag in)
49+
- fix [1557](https://github.com/gridstack/gridstack.js/pull/1557) fix no-drop cursor on windows when dragging within a default grid (no external drag in)
50+
- fix [1541](https://github.com/gridstack/gridstack.js/pull/1541) fix Safari H5 elay when dropping items
5051

5152
## 3.1.3 (2021-1-2)
5253

src/h5/dd-draggable.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ export class DDDraggable extends DDBaseImplement implements HTMLElementExtendOpt
5656
private helperContainment: HTMLElement;
5757
/** @internal */
5858
private static basePosition: 'fixed' | 'absolute' = 'absolute';
59-
/** @internal */
60-
private static dragEventListenerOption = DDUtils.isEventSupportPassiveOption ? { capture: true, passive: true } : true;
59+
/** @internal #1541 can't have {passive: true} on Safari as otherwise it reverts animate back to old location on drop */
60+
private static dragEventListenerOption = true; // DDUtils.isEventSupportPassiveOption ? { capture: true, passive: true } : true;
6161
/** @internal */
6262
private static originStyleProp = ['transition', 'pointerEvents', 'position',
6363
'left', 'top', 'opacity', 'zIndex', 'width', 'height', 'willChange'];
@@ -164,6 +164,9 @@ export class DDDraggable extends DDBaseImplement implements HTMLElementExtendOpt
164164

165165
/** @internal */
166166
private _drag(event: DragEvent): void {
167+
// Safari: prevent default to allow drop to happen instead of reverting back (with animation) and delaying dragend #1541
168+
// https://stackoverflow.com/questions/61760755/how-to-fire-dragend-event-immediately
169+
event.preventDefault();
167170
this._dragFollow(event);
168171
const ev = DDUtils.initEvent<DragEvent>(event, { target: this.el, type: 'drag' });
169172
if (this.option.drag) {

0 commit comments

Comments
 (0)