Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add parts to drag source row cells #7593

Merged
merged 10 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/grid/src/vaadin-grid-drag-and-drop-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ export const DragAndDropMixin = (superClass) =>
updateBooleanRowStates(row, { dragstart: false });
this.style.setProperty('--_grid-drag-start-x', '');
this.style.setProperty('--_grid-drag-start-y', '');
rows.forEach((row) => {
updateBooleanRowStates(row, { 'drag-source': true });
});
});

const event = new CustomEvent('grid-dragstart', {
Expand All @@ -202,6 +205,10 @@ export const DragAndDropMixin = (superClass) =>
const event = new CustomEvent('grid-dragend');
event.originalEvent = e;
this.dispatchEvent(event);

iterateChildren(this.$.items, (row) => {
updateBooleanRowStates(row, { 'drag-source': false });
});
tomivirkki marked this conversation as resolved.
Show resolved Hide resolved
}

/** @private */
Expand Down
3 changes: 2 additions & 1 deletion packages/grid/src/vaadin-grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ registerStyles('vaadin-grid', gridStyles, { moduleId: 'vaadin-grid-styles' });
* `collapsed-row-cell` | Cell in a collapsed row
* `expanded-row-cell` | Cell in an expanded row
* `details-opened-row-cell` | Cell in an row with details open
* `dragstart-row-cell` | Cell in a row that user started to drag (set for one frame)
* `dragstart-row-cell` | Cell in the ghost image row, but not in for a source row
tomivirkki marked this conversation as resolved.
Show resolved Hide resolved
* `drag-source-row-cell` | Cell in a source row, but not in the ghost image
* `dragover-above-row-cell` | Cell in a row that has another row dragged over above
* `dragover-below-row-cell` | Cell in a row that has another row dragged over below
* `dragover-on-top-row-cell` | Cell in a row that has another row dragged over on top
Expand Down
36 changes: 36 additions & 0 deletions packages/grid/test/drag-and-drop.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,42 @@ describe('drag and drop', () => {
});
});

it('should add drag-source- part to all dragged rows', async () => {
grid.selectItem(grid.items[0]);
grid.selectItem(grid.items[1]);
fireDragStart();
await nextFrame();
for (const row of [...grid.$.items.children]) {
for (const cell of [...row.children]) {
tomivirkki marked this conversation as resolved.
Show resolved Hide resolved
expect(cell.getAttribute('part')).to.contain('drag-source-row-cell');
}
}
});

it('should add drag-source- part only to dragged rows', async () => {
fireDragStart();
let cells = getRowBodyCells(getRows(grid.$.items)[0]);
await nextFrame();
for (const cell of cells) {
expect(cell.getAttribute('part')).to.contain('drag-source-row-cell');
}
cells = getRowBodyCells(getRows(grid.$.items)[1]);
for (const cell of cells) {
expect(cell.getAttribute('part')).to.not.contain('drag-source-row-cell');
}
});

it('should remove drag-source- part from row when drag ends', async () => {
fireDragStart();
const row = getRows(grid.$.items)[0];
const cells = getRowBodyCells(row);
await nextFrame();
fireDragEnd();
for (const cell of cells) {
expect(cell.getAttribute('part')).to.not.contain('drag-source-row-cell');
}
});

// The test only concerns Safari
const isSafari = /^((?!chrome|android).)*safari/iu.test(navigator.userAgent);
(isSafari ? it : it.skip)('should use top on Safari for drag image', async () => {
Expand Down
Loading