From 97f32bfd61c4b08c077050eee2fc38c660f6fe1f Mon Sep 17 00:00:00 2001 From: Antonio Campos Date: Tue, 19 Sep 2017 10:36:46 +0200 Subject: [PATCH] Issue 162: rowClassName should accept strings too, not just functions --- README.md | 2 +- src/Table.jsx | 6 +- tests/Table.spec.js | 14 ++++ tests/__snapshots__/Table.spec.js.snap | 100 +++++++++++++++++++++++++ 4 files changed, 119 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2b7285e73..3373da908 100644 --- a/README.md +++ b/README.md @@ -118,7 +118,7 @@ React.render(, mountNode); - + diff --git a/src/Table.jsx b/src/Table.jsx index 40c7c555e..93eebfdd9 100644 --- a/src/Table.jsx +++ b/src/Table.jsx @@ -22,7 +22,7 @@ export default class Table extends React.Component { bodyStyle: PropTypes.object, style: PropTypes.object, rowKey: PropTypes.oneOfType([PropTypes.string, PropTypes.func]), - rowClassName: PropTypes.func, + rowClassName: PropTypes.oneOfType([PropTypes.string, PropTypes.func]), expandedRowClassName: PropTypes.func, childrenColumnName: PropTypes.string, onExpand: PropTypes.func, @@ -325,7 +325,9 @@ export default class Table extends React.Component { if (expandedRowRender && isRowExpanded) { expandedRowContent = expandedRowRender(record, i, indent); } - const className = rowClassName(record, i, indent); + const className = typeof rowClassName === 'string' + ? rowClassName + : rowClassName(record, i, indent); const onHoverProps = {}; if (this.columnManager.isAnyColumnsFixed()) { diff --git a/tests/Table.spec.js b/tests/Table.spec.js index 0eb4c6a0b..26ea2908c 100644 --- a/tests/Table.spec.js +++ b/tests/Table.spec.js @@ -428,4 +428,18 @@ describe('Table', () => { wrapper.find('.rc-table-row').first().simulate('mouseLeave'); expect(handleRowMouseLeave).toBeCalledWith(data[0], 0, expect.anything()); }); + + it('renders correctly RowClassName as string', () => { + const wrapper = render(createTable({ + rowClassName: 'test-row-class-name-asStr', + })); + expect(renderToJson(wrapper)).toMatchSnapshot(); + }); + + it('renders correctly RowClassName as function', () => { + const wrapper = render(createTable({ + rowClassName: () => 'test-row-class-name-asFn', + })); + expect(renderToJson(wrapper)).toMatchSnapshot(); + }); }); diff --git a/tests/__snapshots__/Table.spec.js.snap b/tests/__snapshots__/Table.spec.js.snap index bf7fabe50..ccfda982c 100644 --- a/tests/__snapshots__/Table.spec.js.snap +++ b/tests/__snapshots__/Table.spec.js.snap @@ -219,6 +219,106 @@ exports[`Table renders correctly 1`] = ` `; +exports[`Table renders correctly RowClassName as function 1`] = ` +
+
+
+
rowClassNameFunction(record, index, indent):stringstring or Function(record, index, indent):string get row's className
+ + + + + + + + + + + + + + + + +
+ Name +
+ + Lucy +
+ + Jack +
+ + + +`; + +exports[`Table renders correctly RowClassName as string 1`] = ` +
+
+
+ + + + + + + + + + + + + + + + + +
+ Name +
+ + Lucy +
+ + Jack +
+
+
+
+`; + exports[`Table renders custom cell correctly 1`] = `