Skip to content

Commit

Permalink
fix(table): do not allow the data property to be added to the table e…
Browse files Browse the repository at this point in the history
…lement itself
  • Loading branch information
rdy committed May 28, 2016
1 parent dba6bfb commit efd651b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
30 changes: 30 additions & 0 deletions library/spec/pivotal-ui-react/table/table_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,36 @@ describe('Table', function() {
expect('tbody tr:nth-of-type(2) > td:eq(2)').toContainText(2);
expect('tbody tr:nth-of-type(3) > td:eq(2)').toContainText(3);
});

it('does not render the data as an attribute', () => {
const columns = [
{
attribute: 'title',
displayName: 'Title',
sortable: true
},
{
attribute: 'bar',
displayName: 'Bar',
sortable: true
},
{
attribute: 'theDefault',
displayName: 'DefaultSort',
sortable: true
}
];

const data = [
{ title: 'foo', bar: 'a', theDefault: 3},
{ title: 'sup', bar: 'c', theDefault: 2},
{ title: 'yee', bar: 'b', theDefault: 1}
];

ReactDOM.render(<Table columns={columns} data={data}/>, root);

expect('table').not.toHaveAttr('data');
});
});

describe('TableHeader', function() {
Expand Down
6 changes: 3 additions & 3 deletions library/src/pivotal-ui-react/table/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,13 @@ export class Table extends React.Component {

render() {
const {sortColumn} = this.state;
const {data} = this.props;
const props = mergeProps(this.props, {className: ['table', 'table-sortable', 'table-data']});
let {data, ...props} = this.props;
props = mergeProps(props, {className: ['table', 'table-sortable', 'table-data']});

const rows = (sortColumn === -1) ? this.rows(data) : this.sortedRows();

return (
<table {...props} >
<table {...props}>
<thead>
<tr>{this.renderHeaders()}</tr>
</thead>
Expand Down

0 comments on commit efd651b

Please sign in to comment.