From ae046e2dabf4a1c90b12da7f8fca9738298d9cdc Mon Sep 17 00:00:00 2001 From: Dmitry Kurmanov Date: Tue, 6 Aug 2024 14:20:18 +0400 Subject: [PATCH] PR: LIBRARY: Safari: Unexpected page's focus. (#8651) * work for the https://github.com/surveyjs/survey-creator/issues/5740 * work for the https://github.com/surveyjs/survey-creator/issues/5740 * work for the https://github.com/surveyjs/survey-creator/issues/5740 --- src/dragdrop/core.ts | 5 ++++- tests/dragdrophelpertests.ts | 15 ++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/dragdrop/core.ts b/src/dragdrop/core.ts index e8a9fd7a9a..11357a6ace 100644 --- a/src/dragdrop/core.ts +++ b/src/dragdrop/core.ts @@ -22,6 +22,7 @@ export abstract class DragDropCore implements IDragDropEngine { public onDragStart: EventBase> = new EventBase(); public onDragEnd: EventBase> = new EventBase(); + public onDragClear: EventBase> = new EventBase(); public onBeforeDrop = this.onDragStart; public onAfterDrop = this.onDragEnd; @@ -63,6 +64,8 @@ export abstract class DragDropCore implements IDragDropEngine { event ); this.onStartDrag(event); + const fromElement = this.draggedElement && this.draggedElement.parent; + this.onDragStart.fire(this, { fromElement: fromElement, draggedElement: this.draggedElement }); } protected onStartDrag(event?: PointerEvent): void { @@ -230,7 +233,6 @@ export abstract class DragDropCore implements IDragDropEngine { public drop(): void { if (this.allowDropHere) { const fromElement = this.draggedElement.parent; - this.onDragStart.fire(this, { fromElement: fromElement, draggedElement: this.draggedElement }); const newElement = this.doDrop(); this.onDragEnd.fire(this, { fromElement: fromElement, draggedElement: newElement, toElement: this.dropTarget }); } @@ -242,5 +244,6 @@ export abstract class DragDropCore implements IDragDropEngine { this.draggedElement = null; this.isBottom = null; this.parentElement = null; + this.onDragClear.fire(this, {}); } } diff --git a/tests/dragdrophelpertests.ts b/tests/dragdrophelpertests.ts index 7dd074b581..77d87bf9a7 100644 --- a/tests/dragdrophelpertests.ts +++ b/tests/dragdrophelpertests.ts @@ -116,7 +116,7 @@ QUnit.test("dropTargetDataAttributeName for choices", function (assert) { ); }); -QUnit.test("choices: onDragStart and onDragEnd events", function (assert) { +QUnit.test("choices: onDragStart, onDragEnd, onDragClear events", function (assert) { const survey = new SurveyModel({ elements: [ { @@ -131,6 +131,7 @@ QUnit.test("choices: onDragStart and onDragEnd events", function (assert) { ); let beforeCount = 0; let afterCount = 0; + let clearCount = 0; let draggedElementParent; const ddHelper: any = new DragDropChoices(survey); @@ -141,17 +142,25 @@ QUnit.test("choices: onDragStart and onDragEnd events", function (assert) { afterCount++; draggedElementParent = options.draggedElement; }); + ddHelper.onDragClear.add((sender, options) => { + clearCount++; + }); + ddHelper.parentElement = question; ddHelper.draggedElement = question.choices[2]; + ddHelper["createDraggedElementShortcut"] = ()=>{}; + ddHelper.dragInit(null, ddHelper.draggedElement, ddHelper.parentElement, document.createElement("div")); + assert.equal(beforeCount, 1); + ddHelper["allowDropHere"] = true; ddHelper["domAdapter"]["draggedElementShortcut"] = document.body.appendChild( document.createElement("div") ); - ddHelper["allowDropHere"] = true; ddHelper["drop"](); - assert.equal(beforeCount, 1); assert.equal(afterCount, 1); assert.equal(draggedElementParent.name, "q"); + ddHelper["clear"](); + assert.equal(clearCount, 1); }); QUnit.test("DragDropRankingChoices shortcutClass getter", function (assert) {