Skip to content

Commit

Permalink
Merge branch 'main' into am-pass-rowidx
Browse files Browse the repository at this point in the history
  • Loading branch information
amanmahajan7 authored Nov 22, 2024
2 parents e036cac + a0ba5fa commit 03a8dad
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/DataGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export interface DataGridProps<R, SR = unknown, K extends Key = Key> extends Sha
/** Called when the grid is scrolled */
onScroll?: Maybe<(event: React.UIEvent<HTMLDivElement>) => void>;
/** Called when a column is resized */
onColumnResize?: Maybe<(idx: number, width: number) => void>;
onColumnResize?: Maybe<(column: CalculatedColumn<R, SR>, width: number) => void>;
/** Called when a column is reordered */
onColumnsReorder?: Maybe<(sourceColumnKey: string, targetColumnKey: string) => void>;

Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useColumnWidths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export function useColumnWidths<R, SR>(
updateMeasuredWidths(columnsToMeasure);
});

onColumnResize?.(column.idx, measuredWidth);
onColumnResize?.(column, measuredWidth);
}

return {
Expand Down
6 changes: 5 additions & 1 deletion test/browser/column/resizable.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,16 @@ test('cannot not resize or auto resize column when resizable is not specified',
});

test('should resize column when dragging the handle', async () => {
setup<Row, unknown>({ columns, rows: [] });
const onColumnResize = vi.fn();
setup<Row, unknown>({ columns, rows: [], onColumnResize });
const [, col2] = getHeaderCells();
const grid = getGrid();
expect(onColumnResize).not.toHaveBeenCalled();
await expect.element(grid).toHaveStyle({ gridTemplateColumns: '100px 200px' });
await resize({ column: col2.element(), resizeBy: -50 });
await expect.element(grid).toHaveStyle({ gridTemplateColumns: '100px 150px' });
expect(onColumnResize).toHaveBeenCalledTimes(1);
expect(onColumnResize).toHaveBeenCalledWith(expect.objectContaining(columns[1]), 150);
});

test('should use the maxWidth if specified', async () => {
Expand Down

0 comments on commit 03a8dad

Please sign in to comment.