Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
27 changes: 27 additions & 0 deletions playwright/tests/cell.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,30 @@
expect(await page.locator('.dt-scrollable').evaluate(el => el.scrollTop)).toBe(0);
});
});

test.describe('Cell mouse selection', () => {
test('stops selecting when the mouse is released outside the table', async ({ page }) => {
const center = async (col, row) => {
const box = await getCell(page, col, row).boundingBox();
return [box.x + box.width / 2, box.y + box.height / 2];
};
const highlighted = page.locator('.dt-cell--highlight');

await page.mouse.move(...await center(2, 1));
await page.mouse.down();
await page.mouse.move(...await center(3, 2), { steps: 5 });
await expect(highlighted).toHaveCount(4 + 2);

const table = await page.locator('.datatable').first().boundingBox();
const [, y] = await center(3, 2);
await page.mouse.move(table.x + table.width + 40, y, { steps: 5 });
await page.mouse.up();
const selected = await highlighted.count();

await page.mouse.move(...await center(5, 4), { steps: 5 });
await page.waitForTimeout(200);
await page.mouse.move(...await center(6, 5), { steps: 5 });
await page.waitForTimeout(200);
await expect(highlighted).toHaveCount(selected);

Check failure on line 135 in playwright/tests/cell.spec.js

View workflow job for this annotation

GitHub Actions / test-pull-request

playwright/tests/cell.spec.js:113:9 › Cell mouse selection › stops selecting when the mouse is released outside the table

1) playwright/tests/cell.spec.js:113:9 › Cell mouse selection › stops selecting when the mouse is released outside the table Error: expect(locator).toHaveCount(expected) failed Locator: locator('.dt-cell--highlight') Expected: 2 Received: 10 Timeout: 5000ms Call log: - Expect "toHaveCount" locator('.dt-cell--highlight') with timeout 5000ms - waiting for locator('.dt-cell--highlight') 14 × locator resolved to 10 elements - unexpected value "10" 133 | await page.mouse.move(...await center(6, 5), { steps: 5 }); 134 | await page.waitForTimeout(200); > 135 | await expect(highlighted).toHaveCount(selected); | ^ 136 | }); 137 | }); 138 | at /home/runner/work/datatable/datatable/playwright/tests/cell.spec.js:135:35
});
});
6 changes: 5 additions & 1 deletion src/cellmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,12 @@ export default class CellManager {
this.focusCell($(e.delegatedTarget));
});

$.on(this.bodyScrollable, 'mouseup', () => {
const onMouseup = () => {
mouseDown = false;
};
$.on(document, 'mouseup', onMouseup);
this.instance.on('onDestroy', () => {
$.off(document, 'mouseup', onMouseup);
});

if (this.options.showTotalRow) {
Expand Down
Loading