Skip to content

Commit

Permalink
[PR feedback] Fix rowHeights overrides not triggering a recalculation
Browse files Browse the repository at this point in the history
  • Loading branch information
cee-chen committed Sep 18, 2024
1 parent 4ccf3a1 commit 1f35ef5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,35 @@ describe('EuiDataGridCell', () => {
expect(mockRowHeightUtils.setRowHeight).toHaveBeenCalled();
expect(setRowHeight).not.toHaveBeenCalled();
});

it('recalculates when the override for the row changes', () => {
const component = mount(
<EuiDataGridCell {...requiredProps} setRowHeight={setRowHeight} />
);

component.setProps({
rowHeightsOptions: {
rowHeights: {
0: { lineCount: 2 },
},
},
});
expect(mockRowHeightUtils.setRowHeight).toHaveBeenCalledTimes(1);

// Handle row index changes as well
component.setProps({
rowHeightsOptions: {
rowHeights: {
0: { lineCount: 2 },
2: { lineCount: 4 },
},
},
rowIndex: 2,
});
expect(mockRowHeightUtils.setRowHeight).toHaveBeenCalledTimes(2);

expect(setRowHeight).not.toHaveBeenCalled();
});
});

it('recalculates when props that affect row/line height change', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ export class EuiDataGridCell extends Component<
if (
this.props.rowHeightsOptions?.defaultHeight !==
prevProps.rowHeightsOptions?.defaultHeight ||
this.props.rowHeightsOptions?.rowHeights?.[this.props.rowIndex] !==
prevProps.rowHeightsOptions?.rowHeights?.[prevProps.rowIndex] ||
this.props.rowHeightsOptions?.lineHeight !==
prevProps.rowHeightsOptions?.lineHeight ||
this.props.gridStyles?.fontSize !== prevProps.gridStyles?.fontSize ||
Expand Down

0 comments on commit 1f35ef5

Please sign in to comment.