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

fix(react-components): Fix style prop in DataGridCell breaking resizable columns #33503

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { isConformant } from '../../testing/isConformant';
import { DataGridCellProps } from './DataGridCell.types';
import { DataGridContextProvider } from '../../contexts/dataGridContext';
import { mockDataGridContext } from '../../testing/mockDataGridContext';
import {defaultColumnSizingState} from "../../hooks";

describe('DataGridCell', () => {
isConformant<DataGridCellProps>({
Expand Down Expand Up @@ -65,4 +66,26 @@ describe('DataGridCell', () => {
expect(row.tabIndex).toBe(-1);
expect(row.hasAttribute('tabindex')).toBe(false);
});

it('should merge column sizing styles when a style prop is provided', () => {
const ctx = mockDataGridContext({
resizableColumns: true,
// eslint-disable-next-line @typescript-eslint/naming-convention
columnSizing_unstable: {
...defaultColumnSizingState,
getTableCellProps: ()=> ({
style: { width: 100, minWidth: 100 },
})
}
});
const {getByRole} = render(
<DataGridContextProvider value={ctx}>
<DataGridCell style={{color: 'red', minWidth: 'unset'}}>Default DataGridCell</DataGridCell>
</DataGridContextProvider>,
);
const cell = getByRole('gridcell');
expect(cell).toHaveProperty('style.color', 'red');
expect(cell).toHaveProperty('style.width', '100px');
expect(cell).toHaveProperty('style.minWidth', 'unset');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ export const useDataGridCell_unstable = (props: DataGridCellProps, ref: React.Re
return ctx.columnSizing_unstable.getTableCellProps;
});
const focusableGroupAttr = useFocusableGroup({ tabBehavior: 'limited-trap-focus' });
const style = {
...(resizableColumns ? getTableCellProps(columnId).style : {}),
...(props.style || {}),
};
return useTableCell_unstable(
{
as: 'div',
Expand All @@ -33,6 +37,7 @@ export const useDataGridCell_unstable = (props: DataGridCellProps, ref: React.Re
tabIndex: tabbable ? 0 : undefined,
...(resizableColumns ? getTableCellProps(columnId) : {}),
...props,
style,
},
ref,
);
Expand Down
Loading