Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass column in onColumnResize #3644

Merged
merged 2 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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