Skip to content

Commit e10ead1

Browse files
PR(2): Expanded matrix row doesn't support drag and drop (#10665)
* Expanded matrix row doesn't support drag and drop #10597 * Expanded matrix row doesn't support drag and drop #10597 * Expanded matrix row doesn't support drag and drop #10597 * Expanded matrix row doesn't support drag and drop #10597
1 parent 04a3533 commit e10ead1

File tree

9 files changed

+101
-11
lines changed

9 files changed

+101
-11
lines changed

e2e/questions/matrixdynamic.spec.ts

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { frameworks, url, initSurvey, getSurveyResult, getVisibleListItemByText, test, expect } from "../helper";
1+
import { frameworks, url, initSurvey, getSurveyResult, getVisibleListItemByText, test, expect, setData, getData, doDragDrop } from "../helper";
22

33
const title = "matrixdynamic";
44

@@ -731,5 +731,90 @@ frameworks.forEach((framework) => {
731731
const surveyResult = await getSurveyResult(page);
732732
expect(surveyResult).toEqual({ matrix: [{ col1: "row1" }] });
733733
});
734+
735+
test("DnD: Matrixdynamic inside Matrixdynamic", async ({ page }) => {
736+
await page.setViewportSize({ width: 1280, height: 1100 });
737+
const json = {
738+
"elements": [
739+
{
740+
"type": "matrixdynamic",
741+
"name": "parent",
742+
"columns": [
743+
{
744+
"name": "parent-text",
745+
"cellType": "text"
746+
}
747+
],
748+
"detailElements": [
749+
{
750+
"type": "matrixdynamic",
751+
"name": "child",
752+
"columns": [
753+
{
754+
"name": "child-text",
755+
"cellType": "text",
756+
}
757+
],
758+
"rowCount": 2,
759+
"allowRowReorder": true
760+
}
761+
],
762+
"detailPanelMode": "underRowSingle",
763+
"detailPanelShowOnAdding": true,
764+
"rowCount": 2,
765+
"allowRowReorder": true
766+
}
767+
]
768+
};
769+
770+
const data = {
771+
"parent": [
772+
{
773+
"parent-text": "parent text 1",
774+
"child": [
775+
{
776+
"child-text": "child text 1"
777+
},
778+
{
779+
"child-text": "child text 2"
780+
}
781+
]
782+
},
783+
{
784+
"parent-text": "parent text 2"
785+
}
786+
]
787+
};
788+
789+
await initSurvey(page, framework, json);
790+
await setData(page, data);
791+
792+
await page.getByRole("button", { name: "Show Details" }).first().click();
793+
const row1 = page.locator(".sd-matrixdynamic .sd-matrixdynamic tbody tr").nth(0);
794+
const row2 = page.locator(".sd-matrixdynamic .sd-matrixdynamic tbody tr").nth(1);
795+
const dragIcon = row1.locator(".sd-table__cell--drag .sd-drag-element__svg");
796+
797+
await row1.hover();
798+
await doDragDrop({ page, element: dragIcon, target: row2 });
799+
800+
expect(await getData(page)).toEqual({
801+
"parent": [
802+
{
803+
"parent-text": "parent text 1",
804+
"child": [
805+
{
806+
"child-text": "child text 2"
807+
},
808+
{
809+
"child-text": "child text 1"
810+
},
811+
]
812+
},
813+
{
814+
"parent-text": "parent text 2"
815+
}
816+
]
817+
});
818+
});
734819
});
735820
});

packages/survey-angular-ui/src/components/matrix-actions/drag-drop-icon/drag-drop-icon.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<ng-template #template>
2-
<div>
2+
<div (pointerdown)="question.onPointerDown($event, row)">
33
<svg *ngIf="question.iconDragElement" [class]="question.cssClasses.dragElementDecorator">
44
<use [attr.xlink:href]="question.iconDragElement"></use>
55
</svg>

packages/survey-angular-ui/src/components/matrix-actions/drag-drop-icon/drag-drop-icon.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Component, Input } from "@angular/core";
22
import { AngularComponentFactory } from "../../../component-factory";
3-
import { IAction } from "survey-core";
3+
import { IAction, MatrixDropdownRowModelBase } from "survey-core";
44
import { EmbeddedViewContentComponent } from "../../../embedded-view-content.component";
55

66
@Component({
@@ -14,6 +14,10 @@ export class MatrixDynamicDragDropIconComponent extends EmbeddedViewContentCompo
1414
get question() {
1515
return this.model.data.question;
1616
}
17+
18+
get row(): MatrixDropdownRowModelBase {
19+
return this.model.data.row;
20+
}
1721
}
1822

1923
AngularComponentFactory.Instance.registerComponent(

packages/survey-angular-ui/src/questions/matrix-row.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<ng-template #template>
2-
<tr *ngIf="model.visible" [class]="model.className" (pointerdown)="question.onPointerDown($event, row)"
2+
<tr *ngIf="model.visible" [class]="model.className"
33
[attr.data-sv-drop-target-matrix-row]="model.dropTargetId" #container>
44
<sv-ng-matrixdropdown-cell [cell]="cell" [question]="question"
55
*ngFor="let cell of model.cells; trackBy: trackCellBy"></sv-ng-matrixdropdown-cell>

packages/survey-react-ui/src/components/matrix-actions/drag-drop-icon/drag-drop-icon.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import * as React from "react";
2-
import { QuestionMatrixDropdownModelBase } from "survey-core";
2+
import { MatrixDropdownRowModelBase, QuestionMatrixDropdownModelBase } from "survey-core";
33
import { ReactElementFactory } from "../../../element-factory";
44
import { ReactSurveyElement } from "../../../reactquestion_element";
55

66
export class SurveyQuestionMatrixDynamicDragDropIcon extends ReactSurveyElement {
77
private get question(): QuestionMatrixDropdownModelBase {
88
return this.props.item.data.question;
99
}
10+
private get row(): MatrixDropdownRowModelBase {
11+
return this.props.item.data.row;
12+
}
1013
protected renderElement(): React.JSX.Element | null {
11-
return <div>{this.renderIcon()}</div>;
14+
return <div onPointerDown={(event: any) => { this.question.onPointerDown(event.nativeEvent, this.row); }}>{this.renderIcon()}</div>;
1215
}
1316
protected renderIcon(): React.JSX.Element {
1417
if (this.question.iconDragElement) {

packages/survey-react-ui/src/components/matrix/row.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ export class MatrixRow extends SurveyElementBase<IMatrixRowProps, any> {
5959
ref={this.root}
6060
className={model.className}
6161
data-sv-drop-target-matrix-row={model.dropTargetId}
62-
onPointerDown={(event: any) => this.onPointerDownHandler(event)}
6362
>
6463
{this.props.children}
6564
</tr>

packages/survey-vue3-ui/src/MatrixDropdownRow.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<template>
22
<tr
33
:data-sv-drop-target-matrix-row="row.dropTargetId"
4-
@pointerdown="question.onPointerDown($event, row.row)"
54
:class="row.className"
65
v-if="row.visible"
76
ref="root"

packages/survey-vue3-ui/src/components/matrix-actions/drag-drop-icon/DragDropIcon.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<div>
2+
<div @pointerdown="question.onPointerDown($event, row)">
33
<svg
44
v-if="question.iconDragElement"
55
:class="question.cssClasses.dragElementDecorator"
@@ -14,5 +14,5 @@
1414
import type { Action } from "survey-core";
1515
import { useMatrixAction } from "../matrix-action";
1616
const props = defineProps<{ item: Action }>();
17-
const { question } = useMatrixAction(props, false);
17+
const { question, row } = useMatrixAction(props, true);
1818
</script>

screenshots/matrixdynamic.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { test, expect } from "@playwright/test";
2-
import { frameworks, url, initSurvey, compareScreenshot, resetFocusToBody } from "../e2e/helper";
2+
import { frameworks, url, initSurvey, compareScreenshot, resetFocusToBody, doDrag, setData, doDragDrop } from "../e2e/helper";
33

44
const title = "Matrixdynamic Screenshot";
55

0 commit comments

Comments
 (0)