Skip to content

Commit

Permalink
[EuiDataGrid] Add title attribute to column header cell content (#6013
Browse files Browse the repository at this point in the history
)

* Add default `title` display to column headings

- to make headings more visible if text is being truncated due to column widths

* Update documentation

- clarify props documentation for `displayAsText`
- reorder props by general purpose
- Update `columns` snippet to include all props and also to follow new grouping order

* Changelog

* Fix VO double-announcing column titles on columns without actions

- reproducible on the Version column in the main datagrid example
  • Loading branch information
Constance authored Jun 30, 2022
1 parent 497c730 commit e5d9777
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 14 deletions.
9 changes: 7 additions & 2 deletions src-docs/src/views/datagrid/_snippets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,20 @@ inMemory={{ level: 'sorting' }}`,
columns: `columns={[
{
id: 'A', // required
display: <>Column A <EuiIcon type="dot" /></>, // optional column header rendering
displayAsText: 'Column A', // column header as plain text
initialWidth: 150, // starting width of 150px
isResizable: false, // prevents the user from resizing width
actions: false, // no column header actions are displayed
isExpandable: false, // doesn't allow clicking in to see the content in a popup
actions: { showMoveLeft: false, showMoveRight: false }, // doesn't show move actions in column header
isSortable: false, // prevents the user from sorting the data grid by this column
defaultSortDirection: 'asc', // sets the default sort direction
schema: 'franchise', // custom schema later defined under schemaDetectors
actions: false, // no column header actions are displayed
actions: { showMoveLeft: false, showMoveRight: false }, // doesn't show move actions in column header
cellActions: [ // provides one additional cell action that triggers an alert once clicked
({ Component }) => <Component iconType="heart" onClick={() => alert('test')}>Custom action</Component>,
],
visibleCellActions: 2, // configures the number of cell action buttons immediately visible on a cell
},
]}`,
columnVisibility: `columnVisibility={{
Expand Down
8 changes: 8 additions & 0 deletions src/components/datagrid/__snapshots__/data_grid.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,7 @@ Array [
>
<div
class="euiDataGridHeaderCell__content"
title="A"
>
A
</div>
Expand Down Expand Up @@ -1118,6 +1119,7 @@ Array [
>
<div
class="euiDataGridHeaderCell__content"
title="B"
>
B
</div>
Expand Down Expand Up @@ -1514,6 +1516,7 @@ Array [
>
<div
class="euiDataGridHeaderCell__content"
title="A"
>
A
</div>
Expand Down Expand Up @@ -1557,6 +1560,7 @@ Array [
>
<div
class="euiDataGridHeaderCell__content"
title="B"
>
B
</div>
Expand Down Expand Up @@ -2250,6 +2254,7 @@ Array [
>
<div
class="euiDataGridHeaderCell__content"
title="A"
>
Column A
</div>
Expand Down Expand Up @@ -2293,6 +2298,7 @@ Array [
>
<div
class="euiDataGridHeaderCell__content"
title="B"
>
<div>
More Elements
Expand Down Expand Up @@ -2669,6 +2675,7 @@ Array [
>
<div
class="euiDataGridHeaderCell__content"
title="A"
>
A
</div>
Expand Down Expand Up @@ -2712,6 +2719,7 @@ Array [
>
<div
class="euiDataGridHeaderCell__content"
title="B"
>
B
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ exports[`EuiDataGridBody renders 1`] = `
>
<div
class="euiDataGridHeaderCell__content"
title="columnA"
>
columnA
</div>
Expand Down Expand Up @@ -84,6 +85,7 @@ exports[`EuiDataGridBody renders 1`] = `
>
<div
class="euiDataGridHeaderCell__content"
title="columnB"
>
columnB
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ exports[`EuiDataGridHeaderCell renders 1`] = `
>
<div
className="euiDataGridHeaderCell__content"
title="someColumn"
>
someColumn
</div>
Expand Down
10 changes: 8 additions & 2 deletions src/components/datagrid/body/header/data_grid_header_cell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,10 @@ export const EuiDataGridHeaderCell: FunctionComponent<EuiDataGridHeaderCellProps
{!showColumnActions ? (
<>
{sortingArrow}
<div className="euiDataGridHeaderCell__content">
<div
className="euiDataGridHeaderCell__content"
title={displayAsText || id}
>
{display || displayAsText || id}
</div>
</>
Expand All @@ -158,7 +161,10 @@ export const EuiDataGridHeaderCell: FunctionComponent<EuiDataGridHeaderCellProps
}}
>
{sortingArrow}
<div className="euiDataGridHeaderCell__content">
<div
className="euiDataGridHeaderCell__content"
title={displayAsText || id}
>
{display || displayAsText || id}
</div>
<EuiIcon
Expand Down
23 changes: 13 additions & 10 deletions src/components/datagrid/data_grid_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -539,11 +539,16 @@ export interface EuiDataGridColumn {
*/
display?: ReactNode;
/**
* A Schema to use for the column.
* Built-in values are [`boolean`, `currency`, `datetime`, `numeric`, `json`] but can be expanded by defining your own #EuiDataGrid `schemaDetectors` (for in-memory detection).
* In general, it is advised to pass in a value here when you are sure of the schema ahead of time, so that you don't need to rely on the automatic detection.
* Display name as text for the column.
* This can be used to display a readable column name in column hiding/sorting, where `display` won't be used.
* This will also be used as a `title` attribute that will display on mouseover (useful if the display text is being truncated by the column width).
* If not passed, `id` will be shown as the column name.
*/
schema?: string;
displayAsText?: string;
/**
* Initial width (in pixels) of the column
*/
initialWidth?: number;
/**
* Defaults to true, always true if cellActions are defined. Defines whether or not the column's cells can be expanded with a popup onClick / keydown.
*/
Expand All @@ -552,10 +557,6 @@ export interface EuiDataGridColumn {
* Whether this column's width can be changed by the user, defaults to true
*/
isResizable?: boolean;
/**
* Initial width (in pixels) of the column
*/
initialWidth?: number;
/**
* Whether this column is sortable
*/
Expand All @@ -565,9 +566,11 @@ export interface EuiDataGridColumn {
*/
defaultSortDirection?: 'asc' | 'desc';
/**
* Display name as text for column. This can be used to display column name in column selector and column sorting where `display` won't be used. If not used `id` will be shown as column name in column selector and column sorting.
* A Schema to use for the column.
* Built-in values are [`boolean`, `currency`, `datetime`, `numeric`, `json`] but can be expanded by defining your own #EuiDataGrid `schemaDetectors` (for in-memory detection).
* In general, it is advised to pass in a value here when you are sure of the schema ahead of time, so that you don't need to rely on the automatic detection.
*/
displayAsText?: string;
schema?: string;
/**
* Configuration of column actions. Set to false to disable or use #EuiDataGridColumnActions to configure the actions displayed in the header cell of the column.
*/
Expand Down
1 change: 1 addition & 0 deletions upcoming_changelogs/6013.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Added a default `title` to `EuiDataGrid`'s column headers, allowing header text to remain visible if truncated due to column widths

0 comments on commit e5d9777

Please sign in to comment.