Skip to content

Commit

Permalink
PR: LIBRARY: Safari: Unexpected page's focus. (#8651)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitry-kurmanov authored Aug 6, 2024
1 parent 82badd3 commit ae046e2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/dragdrop/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export abstract class DragDropCore<T> implements IDragDropEngine {

public onDragStart: EventBase<DragDropCore<T>> = new EventBase();
public onDragEnd: EventBase<DragDropCore<T>> = new EventBase();
public onDragClear: EventBase<DragDropCore<T>> = new EventBase();
public onBeforeDrop = this.onDragStart;
public onAfterDrop = this.onDragEnd;

Expand Down Expand Up @@ -63,6 +64,8 @@ export abstract class DragDropCore<T> 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 {
Expand Down Expand Up @@ -230,7 +233,6 @@ export abstract class DragDropCore<T> 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 });
}
Expand All @@ -242,5 +244,6 @@ export abstract class DragDropCore<T> implements IDragDropEngine {
this.draggedElement = null;
this.isBottom = null;
this.parentElement = null;
this.onDragClear.fire(this, {});
}
}
15 changes: 12 additions & 3 deletions tests/dragdrophelpertests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
{
Expand All @@ -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);
Expand All @@ -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) {
Expand Down

0 comments on commit ae046e2

Please sign in to comment.