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

[EuiDataGrid] Add new beta rowHeightsOptions.autoBelowLineCount feature flag #8096

Merged
merged 9 commits into from
Oct 25, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,30 @@ describe('EuiDataGridCell', () => {
expect(component.find('.eui-textBreakWord').exists()).toBe(true);
expect(component.find('.euiTextBlockTruncate').exists()).toBe(true);
});

test('autoBelowLineCount', () => {
mockRowHeightUtils.isAutoBelowLineCount.mockReturnValue(true);

const component = mount(
<EuiDataGridCell
{...props}
rowHeightsOptions={{
autoBelowLineCount: true,
defaultHeight: { lineCount: 3 },
}}
/>
);

expect(
component
.find('div.euiDataGridRowCell__content--autoBelowLineCountHeight')
.hasClass(/autoHeight/)
).toBe(true);
expect(component.find('.eui-textBreakWord').exists()).toBe(true);
expect(component.find('.euiTextBlockTruncate').exists()).toBe(true);

mockRowHeightUtils.isAutoBelowLineCount.mockRestore();
});
});

// Note: Tests for cell interactivity (focus, tabbing, etc) are in `focus_utils.spec.tsx`
Expand Down
28 changes: 16 additions & 12 deletions packages/eui/src/components/datagrid/body/cell/data_grid_cell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const EuiDataGridCellContent: FunctionComponent<
setCellContentsRef,
rowIndex,
colIndex,
rowHeight,
rowHeightsOptions,
rowHeightUtils,
isControlColumn,
...rest
Expand All @@ -78,11 +78,18 @@ const EuiDataGridCellContent: FunctionComponent<
const CellElement =
renderCellValue as JSXElementConstructor<EuiDataGridCellValueElementProps>;

const cellHeightType = useMemo(
() => rowHeightUtils?.getHeightType(rowHeight) || 'default',
[rowHeightUtils, rowHeight]
// Cell height type
const rowHeight = rowHeightUtils?.getRowHeightOption(
rowIndex,
rowHeightsOptions
);
const cellHeightType = useMemo(() => {
return rowHeightUtils?.isAutoBelowLineCount(rowHeightsOptions, rowHeight)
? 'autoBelowLineCount'
mgadewoll marked this conversation as resolved.
Show resolved Hide resolved
: rowHeightUtils?.getHeightType(rowHeight) || 'default';
}, [rowHeightUtils, rowHeight, rowHeightsOptions]);

// Classes and styles
const classes = useMemo(
() =>
classNames(
Expand All @@ -104,7 +111,7 @@ const EuiDataGridCellContent: FunctionComponent<
: [
// Regular data cells should always inherit height from the row wrapper,
// except for auto height
cellHeightType === 'auto'
cellHeightType === 'auto' || cellHeightType === 'autoBelowLineCount'
? styles.content.autoHeight
: styles.content.defaultHeight,
]),
Expand All @@ -113,7 +120,9 @@ const EuiDataGridCellContent: FunctionComponent<
return (
<RenderTruncatedCellContent
hasLineCountTruncation={
cellHeightType === 'lineCount' && !isControlColumn
(cellHeightType === 'lineCount' ||
cellHeightType === 'autoBelowLineCount') &&
!isControlColumn
}
rowHeight={rowHeight}
>
Expand Down Expand Up @@ -591,11 +600,6 @@ export class EuiDataGridCell extends Component<
...cellPropsStyle, // apply anything from setCellProps({ style })
};

const rowHeight = rowHeightUtils?.getRowHeightOption(
rowIndex,
rowHeightsOptions
);

const row =
rowManager && !IS_JEST_ENVIRONMENT
? rowManager.getRow({
Expand Down Expand Up @@ -634,7 +638,7 @@ export class EuiDataGridCell extends Component<
isExpandable={isExpandable}
isExpanded={popoverIsOpen}
setCellContentsRef={this.setCellContentsRef}
rowHeight={rowHeight}
rowHeightsOptions={rowHeightsOptions}
rowHeightUtils={rowHeightUtils}
isControlColumn={isControlColumn}
rowIndex={rowIndex}
Expand Down
3 changes: 2 additions & 1 deletion packages/eui/src/components/datagrid/data_grid.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ export const euiDataGridStyles = (euiThemeContext: UseEuiTheme) => {
}

/* Workaround to trim line-clamp and padding - @see https://github.com/elastic/eui/issues/7780 */
.euiDataGridRowCell__content--lineCountHeight {
.euiDataGridRowCell__content--lineCountHeight,
.euiDataGridRowCell__content--autoBelowLineCountHeight {
${logicalCSS('padding-bottom', 0)}
${logicalCSS(
'border-bottom',
Expand Down