-
Notifications
You must be signed in to change notification settings - Fork 834
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ensure gridStyle fontSize and cellPadding trigger recalculation …
…of cell line height
- Loading branch information
Showing
5 changed files
with
55 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
packages/eui/src/components/datagrid/utils/cell_heights.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { useEffect, useRef, useState } from 'react'; | ||
|
||
import { EuiDataGridBodyProps } from '../data_grid_types'; | ||
|
||
export const useShouldUpdateCellLineHeight = ( | ||
gridStyles: EuiDataGridBodyProps['gridStyles'] | ||
) => { | ||
const _gridStyles = useRef(gridStyles); | ||
const [shouldUpdateLineHeight, setShouldUpdateLineHeight] = useState(false); | ||
|
||
useEffect(() => { | ||
if ( | ||
gridStyles && | ||
(_gridStyles.current?.fontSize || _gridStyles.current?.cellPadding) | ||
) { | ||
const hasNewFontSize = _gridStyles.current?.fontSize | ||
? _gridStyles.current?.fontSize !== gridStyles?.fontSize | ||
: false; | ||
const hasNewCellPadding = _gridStyles.current?.cellPadding | ||
? _gridStyles.current?.cellPadding !== gridStyles?.cellPadding | ||
: false; | ||
|
||
setShouldUpdateLineHeight(hasNewFontSize || hasNewCellPadding); | ||
|
||
_gridStyles.current = gridStyles; | ||
} | ||
}, [gridStyles]); | ||
|
||
return shouldUpdateLineHeight; | ||
}; |