Skip to content

Commit

Permalink
resize event fired for multiple column
Browse files Browse the repository at this point in the history
  • Loading branch information
shaharyar-shamshi committed Feb 27, 2024
1 parent d56332d commit 57a4903
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -724,16 +724,14 @@ export const useGridColumnResize = (

apiRef.current.updateColumns(newColumns);

if (colDefRef.current) {
const columnsState = gridColumnsStateSelector(apiRef.current.state);
const column: GridStateColDef = columnsState.lookup[colDefRef.current.field];
const width: number = column.width as number;
newColumns.forEach((newColumn) => {
const width: number = newColumn.width as number;
apiRef.current.publishEvent('columnWidthChange', {
element: apiRef.current.getColumnHeaderElement(colDefRef.current.field),
colDef: { ...colDefRef.current, width },
element: apiRef.current.getColumnHeaderElement(newColumn.field),
colDef: newColumn,
width,
});
}
});
} finally {
apiRef.current.unstable_setColumnVirtualization(true);
isAutosizingRef.current = false;
Expand Down
10 changes: 7 additions & 3 deletions packages/x-data-grid-pro/src/tests/columns.DataGridPro.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,13 @@ describe('<DataGridPro /> - Columns', () => {
expect(onColumnWidthChange.args[0][0].width).to.equal(120);
fireEvent.doubleClick(separator);
await microtasks();
expect(onColumnWidthChange.callCount).to.equal(2);
expect(onColumnWidthChange.args[1][0].width).to.equal(116);
expect(onColumnWidthChange.args[1][0].colDef.width).to.equal(116);
expect(onColumnWidthChange.callCount).to.be.at.least(2);
const widthArgs = onColumnWidthChange.args.map((arg) => arg[0].width);
const isWidth116Present = widthArgs.some((width) => width === 116);
expect(isWidth116Present).to.equal(true);
const colDefWidthArgs = onColumnWidthChange.args.map((arg) => arg[0].colDef.width);
const isColDefWidth116Present = colDefWidthArgs.some((width) => width === 116);
expect(isColDefWidth116Present).to.equal(true);
});

it('should not affect other cell elements that are not part of the main DataGrid instance', () => {
Expand Down

0 comments on commit 57a4903

Please sign in to comment.