diff --git a/src/components/datagrid/__mocks__/row_height_utils.ts b/src/components/datagrid/__mocks__/row_height_utils.ts index 7938408c309..3e0c7b53520 100644 --- a/src/components/datagrid/__mocks__/row_height_utils.ts +++ b/src/components/datagrid/__mocks__/row_height_utils.ts @@ -21,6 +21,7 @@ export const mockRowHeightUtils = ({ isDefinedHeight: jest.fn(() => true), isAutoHeight: jest.fn(() => false), setRowHeight: jest.fn(), + unsetRowHeight: jest.fn(), getRowHeight: jest.fn(() => 32), getComputedCellStyles: jest.fn(() => {}), getCalculatedHeight: jest.fn( diff --git a/src/components/datagrid/body/__snapshots__/data_grid_cell.test.tsx.snap b/src/components/datagrid/body/__snapshots__/data_grid_cell.test.tsx.snap index f379b709957..b6ac13bafe5 100644 --- a/src/components/datagrid/body/__snapshots__/data_grid_cell.test.tsx.snap +++ b/src/components/datagrid/body/__snapshots__/data_grid_cell.test.tsx.snap @@ -19,6 +19,7 @@ exports[`EuiDataGridCell renders 1`] = ` "isDefinedHeight": [MockFunction], "setGrid": [MockFunction], "setRowHeight": [MockFunction], + "unsetRowHeight": [MockFunction], } } rowIndex={0} @@ -65,6 +66,7 @@ exports[`EuiDataGridCell renders 1`] = ` "isDefinedHeight": [MockFunction], "setGrid": [MockFunction], "setRowHeight": [MockFunction], + "unsetRowHeight": [MockFunction], } } rowIndex={0} diff --git a/src/components/datagrid/body/data_grid_cell.tsx b/src/components/datagrid/body/data_grid_cell.tsx index 04e985ad269..6454956c8c7 100644 --- a/src/components/datagrid/body/data_grid_cell.tsx +++ b/src/components/datagrid/body/data_grid_cell.tsx @@ -233,6 +233,13 @@ export class EuiDataGridCell extends Component< if (this.unsubscribeCell) { this.unsubscribeCell(); } + + const { rowIndex, colIndex, visibleRowIndex } = this.props; + this.props.rowHeightUtils?.unsetRowHeight( + rowIndex, + colIndex, + visibleRowIndex + ); } componentDidUpdate(prevProps: EuiDataGridCellProps) { diff --git a/src/components/datagrid/row_height_utils.ts b/src/components/datagrid/row_height_utils.ts index b97fe912e98..4405de33c52 100644 --- a/src/components/datagrid/row_height_utils.ts +++ b/src/components/datagrid/row_height_utils.ts @@ -71,6 +71,16 @@ export class RowHeightUtils { rowHeights[colIndex] = adaptedHeight; this.heightsCache.set(rowIndex, rowHeights); + this.resetRow(visibleRowIndex); + } + + unsetRowHeight(rowIndex: number, colIndex: number, visibleRowIndex: number) { + const rowHeights = this.heightsCache.get(rowIndex) || {}; + delete rowHeights[colIndex]; + this.resetRow(visibleRowIndex); + } + + resetRow(visibleRowIndex: number) { // save the first row index of batch, reassigning it only // if this visible row index less than lastUpdatedRow this.lastUpdatedRow = Math.min(this.lastUpdatedRow, visibleRowIndex);