diff --git a/src/dragdrop/ranking-select-to-rank.ts b/src/dragdrop/ranking-select-to-rank.ts index 63a4628aa3..1f384289c2 100644 --- a/src/dragdrop/ranking-select-to-rank.ts +++ b/src/dragdrop/ranking-select-to-rank.ts @@ -91,7 +91,10 @@ export class DragDropRankingSelectToRank extends DragDropRankingChoices { let fromIndex = fromChoicesArray.indexOf(this.draggedElement); let toIndex = toChoicesArray.indexOf(this.dropTarget); - if (toIndex === -1) toIndex = model.value.length; + if (toIndex === -1) { + const length = model.value.length; + toIndex = fromChoicesArray === toChoicesArray ? length - 1 : length; + } return { fromIndex, toIndex }; } diff --git a/tests/dragdrophelpertests.ts b/tests/dragdrophelpertests.ts index aa60e348b0..73215744d2 100644 --- a/tests/dragdrophelpertests.ts +++ b/tests/dragdrophelpertests.ts @@ -309,8 +309,10 @@ QUnit.test("DragDropRankingSelectToRank getIndixies", function (assert) { const dndModel = new DragDropRankingSelectToRank(); const questionModel = createRankingQuestionModel(withDefaultValue); - let { toIndex } = dndModel.getIndixies(questionModel, questionModel.rankingChoices, questionModel.unRankingChoices); + let toIndex = dndModel.getIndixies(questionModel, questionModel.rankingChoices, questionModel.unRankingChoices).toIndex; assert.equal(toIndex, 2); + toIndex = dndModel.getIndixies(questionModel, questionModel.rankingChoices, questionModel.rankingChoices).toIndex; + assert.equal(toIndex, 1); }); // EO selectToRankEnabled