diff --git a/src/DragHandle.tsx b/src/DragHandle.tsx index 05d575bb4c..3497d95470 100644 --- a/src/DragHandle.tsx +++ b/src/DragHandle.tsx @@ -59,6 +59,8 @@ export default function DragHandle({ const column = columns[idx]; function handleMouseDown(event: React.MouseEvent) { + // keep the focus on the cell + event.preventDefault(); if (event.buttons !== 1) return; setDragging(true); window.addEventListener('mouseover', onMouseOver); diff --git a/test/dragFill.test.tsx b/test/dragFill.test.tsx index f5264b5d48..0b785d3175 100644 --- a/test/dragFill.test.tsx +++ b/test/dragFill.test.tsx @@ -68,8 +68,11 @@ test('should not allow dragFill if onFill is undefined', async () => { test('should allow dragFill if onFill is specified', async () => { setup(); - await userEvent.click(getCellsAtRowIndex(0)[0]); + const cell = getCellsAtRowIndex(0)[0]; + await userEvent.click(cell); + expect(cell).toHaveFocus(); await userEvent.dblClick(getDragHandle()!); + expect(cell).toHaveFocus(); expect(getCellsAtRowIndex(1)[0]).toHaveTextContent('a1'); expect(getCellsAtRowIndex(2)[0]).toHaveTextContent('a1'); expect(getCellsAtRowIndex(3)[0]).toHaveTextContent('a4'); // readonly cell @@ -77,7 +80,8 @@ test('should allow dragFill if onFill is specified', async () => { test('should update single row using mouse', async () => { setup(); - await userEvent.click(getCellsAtRowIndex(0)[0]); + const cell = getCellsAtRowIndex(0)[0]; + await userEvent.click(cell); await userEvent.pointer([ { keys: '[MouseLeft>]', target: getDragHandle()! }, { target: getRows()[1] }, @@ -85,6 +89,7 @@ test('should update single row using mouse', async () => { ]); expect(getCellsAtRowIndex(1)[0]).toHaveTextContent('a1'); expect(getCellsAtRowIndex(2)[0]).toHaveTextContent('a3'); + expect(cell).toHaveFocus(); }); test('should update multiple rows using mouse', async () => {