Skip to content

Commit

Permalink
Update grid cells to dogfood EuiTextBlockTruncate
Browse files Browse the repository at this point in the history
  • Loading branch information
cee-chen committed Oct 4, 2023
1 parent 901a3aa commit 5957ca2
Showing 1 changed file with 45 additions and 28 deletions.
73 changes: 45 additions & 28 deletions src/components/datagrid/body/data_grid_cell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { keys } from '../../../services';
import { EuiScreenReaderOnly } from '../../accessibility';
import { EuiFocusTrap } from '../../focus_trap';
import { EuiI18n } from '../../i18n';
import { EuiTextBlockTruncate } from '../../text_truncate';
import { hasResizeObserver } from '../../observer/resize_observer/resize_observer';
import { DataGridFocusContext } from '../utils/focus';
import { RowHeightVirtualizationUtils } from '../utils/row_heights';
Expand Down Expand Up @@ -83,36 +84,52 @@ const EuiDataGridCellContent: FunctionComponent<
}
);

let cellContent = (
<div
ref={setCellContentsRef}
data-datagrid-cellcontent
className={classes}
>
<CellElement
isDetails={false}
data-test-subj="cell-content"
rowIndex={rowIndex}
colIndex={colIndex}
schema={column?.schema || rest.columnType}
{...rest}
/>
</div>
);
if (cellHeightType === 'lineCount' && !isControlColumn) {
const lines = rowHeightUtils!.getLineCount(rowHeightOption)!;
cellContent = (
<EuiTextBlockTruncate lines={lines} cloneElement>
{cellContent}
</EuiTextBlockTruncate>
);
}

const screenReaderText = (
<EuiScreenReaderOnly>
<p hidden={!isFocused}>
{'- '}
<EuiI18n
token="euiDataGridCell.position"
default="{columnId}, column {col}, row {row}"
values={{
columnId: column?.displayAsText || rest.columnId,
col: colIndex + 1,
row: ariaRowIndex,
}}
/>
</p>
</EuiScreenReaderOnly>
);

return (
<>
<div
ref={setCellContentsRef}
data-datagrid-cellcontent
className={classes}
>
<CellElement
isDetails={false}
data-test-subj="cell-content"
rowIndex={rowIndex}
colIndex={colIndex}
schema={column?.schema || rest.columnType}
{...rest}
/>
</div>
<EuiScreenReaderOnly>
<p hidden={!isFocused}>
{'- '}
<EuiI18n
token="euiDataGridCell.position"
default="{columnId}, column {col}, row {row}"
values={{
columnId: column?.displayAsText || rest.columnId,
col: colIndex + 1,
row: ariaRowIndex,
}}
/>
</p>
</EuiScreenReaderOnly>
{cellContent}
{screenReaderText}
</>
);
}
Expand Down

0 comments on commit 5957ca2

Please sign in to comment.