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

[DataGrid] Make column autosizing work with flex columns (@cherniavskii) #15712

Merged
merged 1 commit into from
Dec 3, 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
55 changes: 27 additions & 28 deletions packages/x-data-grid-pro/src/tests/columns.DataGridPro.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,9 @@ describe('<DataGridPro /> - Columns', () => {
const baselineProps = {
autoHeight: isJSDOM,
rows: [
{
id: 0,
brand: 'Nike',
},
{
id: 1,
brand: 'Adidas',
},
{
id: 2,
brand: 'Puma',
},
{ id: 0, brand: 'Nike' },
{ id: 1, brand: 'Adidas' },
{ id: 2, brand: 'Puma' },
],
columns: [{ field: 'brand' }],
};
Expand Down Expand Up @@ -443,22 +434,10 @@ describe('<DataGridPro /> - Columns', () => {
});

const rows = [
{
id: 0,
brand: 'Nike',
},
{
id: 1,
brand: 'Adidas',
},
{
id: 2,
brand: 'Puma',
},
{
id: 3,
brand: 'Lululemon Athletica',
},
{ id: 0, brand: 'Nike' },
{ id: 1, brand: 'Adidas' },
{ id: 2, brand: 'Puma' },
{ id: 3, brand: 'Lululemon Athletica' },
];
const columns = [
{ field: 'id', headerName: 'This is the ID column' },
Expand Down Expand Up @@ -493,6 +472,26 @@ describe('<DataGridPro /> - Columns', () => {
expect(getWidths()).to.deep.equal([155, 177]);
});

it('should work with flex columns', async () => {
render(
<Test
rows={rows}
columns={[
{ field: 'id', flex: 1 },
{ field: 'brand', flex: 2 },
]}
/>,
);
const separators = document.querySelectorAll(`.${gridClasses['columnSeparator--resizable']}`);
fireEvent.doubleClick(separators[0]);
await microtasks();
expect(columns.map((_, i) => getColumnHeaderCell(i).offsetWidth)).to.deep.equal([50, 233]);

fireEvent.doubleClick(separators[1]);
await microtasks();
expect(columns.map((_, i) => getColumnHeaderCell(i).offsetWidth)).to.deep.equal([50, 64]);
});

describe('options', () => {
const autosize = async (options: GridAutosizeOptions | undefined, widths: number[]) => {
render(<Test rows={rows} columns={columns} />);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,7 @@ export const useGridColumnResize = (
...column,
width: widthByField[column.field],
computedWidth: widthByField[column.field],
flex: 0,
}));

if (options.expand) {
Expand Down