Skip to content

Commit a0ba5fa

Browse files
authored
Pass column in onColumnResize (#3644)
* Pass column in `onColumnResize ` * Add a test
1 parent 041357f commit a0ba5fa

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

src/DataGrid.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ export interface DataGridProps<R, SR = unknown, K extends Key = Key> extends Sha
187187
/** Called when the grid is scrolled */
188188
onScroll?: Maybe<(event: React.UIEvent<HTMLDivElement>) => void>;
189189
/** Called when a column is resized */
190-
onColumnResize?: Maybe<(idx: number, width: number) => void>;
190+
onColumnResize?: Maybe<(column: CalculatedColumn<R, SR>, width: number) => void>;
191191
/** Called when a column is reordered */
192192
onColumnsReorder?: Maybe<(sourceColumnKey: string, targetColumnKey: string) => void>;
193193

src/hooks/useColumnWidths.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export function useColumnWidths<R, SR>(
9696
updateMeasuredWidths(columnsToMeasure);
9797
});
9898

99-
onColumnResize?.(column.idx, measuredWidth);
99+
onColumnResize?.(column, measuredWidth);
100100
}
101101

102102
return {

test/browser/column/resizable.test.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,16 @@ test('cannot not resize or auto resize column when resizable is not specified',
6464
});
6565

6666
test('should resize column when dragging the handle', async () => {
67-
setup<Row, unknown>({ columns, rows: [] });
67+
const onColumnResize = vi.fn();
68+
setup<Row, unknown>({ columns, rows: [], onColumnResize });
6869
const [, col2] = getHeaderCells();
6970
const grid = getGrid();
71+
expect(onColumnResize).not.toHaveBeenCalled();
7072
await expect.element(grid).toHaveStyle({ gridTemplateColumns: '100px 200px' });
7173
await resize({ column: col2.element(), resizeBy: -50 });
7274
await expect.element(grid).toHaveStyle({ gridTemplateColumns: '100px 150px' });
75+
expect(onColumnResize).toHaveBeenCalledTimes(1);
76+
expect(onColumnResize).toHaveBeenCalledWith(expect.objectContaining(columns[1]), 150);
7377
});
7478

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

0 commit comments

Comments
 (0)