From 5ef8582c3fd17efa1aa0df9498df2398bb81de1f Mon Sep 17 00:00:00 2001 From: CJ Cenizal Date: Thu, 24 May 2018 16:53:06 -0700 Subject: [PATCH] Add rowProps and cellProps props. Apply pass-through cell props directly to the td element instead of the child div. --- CHANGELOG.md | 7 ++- src-docs/src/views/tables/basic/basic.js | 27 ++++++--- .../src/views/tables/basic/basic_section.js | 9 +-- .../__snapshots__/basic_table.test.js.snap | 3 - src/components/basic_table/basic_table.js | 57 +++++++++++++++---- .../basic_table/basic_table.test.js | 14 ++--- .../__snapshots__/table_row_cell.test.js.snap | 4 +- src/components/table/table_row_cell.js | 4 +- 8 files changed, 84 insertions(+), 41 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b57b0a71564d..314129a1ca9a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,15 @@ ## [`master`](https://github.com/elastic/eui/tree/master) -- `EuiBasicTable` and `EuiInMemoryTable` now let you define a `__props__` object on each row item, -which lets you apply custom props to each row component ([#869](https://github.com/elastic/eui/pull/869)) +- `EuiBasicTable` and `EuiInMemoryTable` now accept `rowProps` and `cellProps` callbacks, +which let you apply custom props to rows and props ([#869](https://github.com/elastic/eui/pull/869)) **Breaking changes** - `EuiSearchBar` no longer has an `onParse` callback, and now passes an object to `onChange` with the shape `{ query, queryText, error }` ([#863](https://github.com/elastic/eui/pull/863)) - `EuiInMemoryTable`'s `search.onChange` callback now passes an object with `{ query, queryText, error }` instead of only the query ([#863](https://github.com/elastic/eui/pull/863)) +- `EuiBasicTable` and `EuiInMemoryTable` pass-through cell props (defined by the `columns` prop +and the `cellProps` prop) used to be applied to the `div` inside of the `td` element. They're +now applied directly to the `td` element. ([#869](https://github.com/elastic/eui/pull/869)) **Bug fixes** diff --git a/src-docs/src/views/tables/basic/basic.js b/src-docs/src/views/tables/basic/basic.js index ba76e3399e6d..0eb966d078a0 100644 --- a/src-docs/src/views/tables/basic/basic.js +++ b/src-docs/src/views/tables/basic/basic.js @@ -80,22 +80,31 @@ export const Table = () => { } }]; - const items = store.users.filter((user, index) => index < 10).map(user => { - const { id } = user; + const items = store.users.filter((user, index) => index < 10); + + const getRowProps = (item) => { + const { id } = item; + return { + 'data-test-subj': `row-${id}`, + className: 'customRowClass', + onClick: () => console.log(`Clicked row ${id}`), + }; + }; + + const getCellProps = (item, column, columnIndex) => { + const { id } = item; return { - ...user, - __props__: { - 'data-test-subj': `row-${id}`, - className: 'customClass', - onClick: () => console.log(`Clicked row ${id}`), - }, + className: 'customCellClass', + 'data-test-subj': `cell-${id}-${columnIndex}`, }; - }); + }; return ( ); }; diff --git a/src-docs/src/views/tables/basic/basic_section.js b/src-docs/src/views/tables/basic/basic_section.js index 419cbfa3ec0b..4221067205b1 100644 --- a/src-docs/src/views/tables/basic/basic_section.js +++ b/src-docs/src/views/tables/basic/basic_section.js @@ -31,10 +31,11 @@ export const section = {