From 25e1684b4836295c020b0080783944ac88bde4e2 Mon Sep 17 00:00:00 2001 From: Ejaaz Khan Date: Sun, 22 Nov 2026 22:15:17 +0530 Subject: [PATCH 1/2] fix: end a drag selection when the mouse is released outside the table --- playwright/tests/cell.spec.js | 24 ++++++++++++++++++++++++ src/cellmanager.js | 6 +++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/playwright/tests/cell.spec.js b/playwright/tests/cell.spec.js index 2be9a2c..3ba294c 100644 --- a/playwright/tests/cell.spec.js +++ b/playwright/tests/cell.spec.js @@ -108,3 +108,27 @@ test.describe('Cell focus in a sorted table', () => { 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); + + await page.mouse.move(20, 300, { steps: 5 }); + await page.mouse.up(); + + 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(4 + 2); + }); +}); diff --git a/src/cellmanager.js b/src/cellmanager.js index 77bec1b..9d4f613 100644 --- a/src/cellmanager.js +++ b/src/cellmanager.js @@ -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) { From 82d63bcc2039e1bc2de92022585f9fb213a19513 Mon Sep 17 00:00:00 2001 From: Ejaaz Khan Date: Sun, 22 Nov 2026 22:19:28 +0530 Subject: [PATCH 2/2] test: release the drag outside the table at a measured point --- playwright/tests/cell.spec.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/playwright/tests/cell.spec.js b/playwright/tests/cell.spec.js index 3ba294c..3dd357a 100644 --- a/playwright/tests/cell.spec.js +++ b/playwright/tests/cell.spec.js @@ -122,13 +122,16 @@ test.describe('Cell mouse selection', () => { await page.mouse.move(...await center(3, 2), { steps: 5 }); await expect(highlighted).toHaveCount(4 + 2); - await page.mouse.move(20, 300, { steps: 5 }); + 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(4 + 2); + await expect(highlighted).toHaveCount(selected); }); });