-
Notifications
You must be signed in to change notification settings - Fork 882
[EuiDataGrid] Fix row height not updating dynamically when set to auto
#5281
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
Changes from 6 commits
17c6eb8
0eab3ab
a553005
6b870fd
10317cb
9eb6651
9e844ea
22aed7a
1e3ded2
4717a89
0149a10
67d27af
03e91d2
6382ca8
bd2e315
ed76e3b
83f7eea
255ae54
4b66cbf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -194,32 +194,24 @@ export class EuiDataGridCell extends Component< | |
| } | ||
| }; | ||
|
|
||
| recalculateRowHeight() { | ||
| const cellRef = this.cellRef.current; | ||
| const { getRowHeight, rowHeightUtils, rowHeightsOptions } = this.props; | ||
|
|
||
| if (cellRef && getRowHeight && rowHeightUtils && rowHeightsOptions) { | ||
| const { rowIndex, colIndex, visibleRowIndex } = this.props; | ||
| setAutoRowHeight = () => { | ||
| const { rowHeightUtils, rowHeightsOptions, rowIndex } = this.props; | ||
| if ( | ||
| this.cellContentsRef && | ||
| rowHeightUtils && | ||
| rowHeightUtils.isAutoHeight(rowIndex, rowHeightsOptions) | ||
| ) { | ||
| const { colIndex, visibleRowIndex } = this.props; | ||
| const rowHeight = this.cellContentsRef.offsetHeight; | ||
|
|
||
| const isAutoHeight = rowHeightUtils.isAutoHeight( | ||
| rowHeightUtils.setRowHeight( | ||
| rowIndex, | ||
| rowHeightsOptions | ||
| ); | ||
| const isHeightSame = rowHeightUtils.compareHeights( | ||
| cellRef.offsetHeight, | ||
| getRowHeight(rowIndex) | ||
| colIndex, | ||
| rowHeight, | ||
| visibleRowIndex | ||
| ); | ||
|
|
||
| if (isAutoHeight && !isHeightSame) { | ||
| rowHeightUtils.setRowHeight( | ||
| rowIndex, | ||
| colIndex, | ||
| this.cellContentsRef?.offsetHeight, | ||
| visibleRowIndex | ||
| ); | ||
| } | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| componentDidMount() { | ||
| this.unsubscribeCell = this.context.onFocusUpdate( | ||
|
|
@@ -244,7 +236,7 @@ export class EuiDataGridCell extends Component< | |
| } | ||
|
|
||
| componentDidUpdate(prevProps: EuiDataGridCellProps) { | ||
| this.recalculateRowHeight(); | ||
| this.setAutoRowHeight(); | ||
|
|
||
| if (this.props.columnId !== prevProps.columnId) { | ||
| this.setCellProps({}); | ||
|
|
@@ -286,22 +278,6 @@ export class EuiDataGridCell extends Component< | |
| if (nextState.disableCellTabIndex !== this.state.disableCellTabIndex) | ||
| return true; | ||
|
|
||
| // check if we should update cell because height was changed | ||
| if ( | ||
| this.cellRef.current && | ||
| nextProps.getRowHeight && | ||
| nextProps.rowHeightUtils | ||
| ) { | ||
| if ( | ||
| !nextProps.rowHeightUtils?.compareHeights( | ||
| this.cellRef.current.offsetHeight, | ||
| nextProps.getRowHeight(nextProps.rowIndex) | ||
| ) | ||
| ) { | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
|
Comment on lines
-289
to
-304
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Quick walkthrough of changes:
|
||
| return false; | ||
| } | ||
|
|
||
|
|
@@ -311,27 +287,10 @@ export class EuiDataGridCell extends Component< | |
|
|
||
| setCellContentsRef = (ref: HTMLDivElement | null) => { | ||
| this.cellContentsRef = ref; | ||
| const { rowHeightUtils, rowHeightsOptions, rowIndex } = this.props; | ||
| if ( | ||
| hasResizeObserver && | ||
| rowHeightUtils && | ||
| rowHeightsOptions && | ||
| rowHeightUtils.isAutoHeight(rowIndex, rowHeightsOptions) | ||
| ) { | ||
| if (ref) { | ||
| const { colIndex, visibleRowIndex } = this.props; | ||
|
|
||
| const setRowHeight = (rowHeight: number) => | ||
| rowHeightUtils.setRowHeight( | ||
| rowIndex, | ||
| colIndex, | ||
| rowHeight, | ||
| visibleRowIndex | ||
| ); | ||
| this.contentObserver = this.observeHeight(ref, setRowHeight); | ||
| } else if (this.contentObserver) { | ||
| this.contentObserver.disconnect(); | ||
| } | ||
| if (ref && hasResizeObserver) { | ||
| this.contentObserver = this.observeHeight(ref, this.setAutoRowHeight); | ||
| } else if (this.contentObserver) { | ||
| this.contentObserver.disconnect(); | ||
| } | ||
| this.preventTabbing(); | ||
| }; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.