Skip to content

Commit

Permalink
Breaking change: pass MouseEvent to onDoubleClickCell (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
platypii authored Dec 16, 2024
1 parent 04d385f commit db92af3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/HighTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -249,7 +249,7 @@ export default function HighTable({
return <td
className={str === undefined ? 'pending' : undefined}
key={col}
onDoubleClick={() => onDoubleClickCell?.(col, rowIndex ?? row)}
onDoubleClick={e => onDoubleClickCell?.(e, col, rowIndex ?? row)}
onMouseDown={e => onMouseDownCell?.(e, col, rowIndex ?? row)}
style={memoizedStyles[col]}
title={title}>
Expand Down
12 changes: 11 additions & 1 deletion test/HighTable.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(<HighTable data={mockData} onMouseDownCell={mockMiddleClick} />)
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 () => {
Expand Down

0 comments on commit db92af3

Please sign in to comment.