From db92af344735f253579e6ea1da0dfb6069ffe48a Mon Sep 17 00:00:00 2001 From: Kenny Daniel Date: Mon, 16 Dec 2024 09:56:37 -0800 Subject: [PATCH] Breaking change: pass MouseEvent to onDoubleClickCell (#14) --- src/HighTable.tsx | 4 ++-- test/HighTable.test.tsx | 12 +++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/HighTable.tsx b/src/HighTable.tsx index d9c3443..1568974 100644 --- a/src/HighTable.tsx +++ b/src/HighTable.tsx @@ -27,7 +27,7 @@ interface TableProps { padding?: number // number of padding rows to render outside of the viewport focus?: boolean // focus table on mount? (default true) tableControl?: TableControl // control the table from outside - onDoubleClickCell?: (col: number, row: number) => void + onDoubleClickCell?: (event: React.MouseEvent, col: number, row: number) => void onMouseDownCell?: (event: React.MouseEvent, col: number, row: number) => void onError?: (error: Error) => void } @@ -249,7 +249,7 @@ export default function HighTable({ return onDoubleClickCell?.(col, rowIndex ?? row)} + onDoubleClick={e => onDoubleClickCell?.(e, col, rowIndex ?? row)} onMouseDown={e => onMouseDownCell?.(e, col, rowIndex ?? row)} style={memoizedStyles[col]} title={title}> diff --git a/test/HighTable.test.tsx b/test/HighTable.test.tsx index ec2e5a0..36f397d 100644 --- a/test/HighTable.test.tsx +++ b/test/HighTable.test.tsx @@ -63,7 +63,17 @@ describe('HighTable', () => { fireEvent.doubleClick(cell) - expect(mockDoubleClick).toHaveBeenCalledWith(1, 0) + expect(mockDoubleClick).toHaveBeenCalledWith(expect.anything(), 1, 0) + }) + + it('correctly handles middle click on cell', async () => { + const mockMiddleClick = vi.fn() + const { findByText } = render() + const cell = await findByText('Name 0') + + fireEvent.mouseDown(cell, { button: 1 }) + + expect(mockMiddleClick).toHaveBeenCalledWith(expect.anything(), 1, 0) }) it('displays error when data fetch fails', async () => {