Skip to content

Commit efd651b

Browse files
committed
fix(table): do not allow the data property to be added to the table element itself
1 parent dba6bfb commit efd651b

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

library/spec/pivotal-ui-react/table/table_spec.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,36 @@ describe('Table', function() {
448448
expect('tbody tr:nth-of-type(2) > td:eq(2)').toContainText(2);
449449
expect('tbody tr:nth-of-type(3) > td:eq(2)').toContainText(3);
450450
});
451+
452+
it('does not render the data as an attribute', () => {
453+
const columns = [
454+
{
455+
attribute: 'title',
456+
displayName: 'Title',
457+
sortable: true
458+
},
459+
{
460+
attribute: 'bar',
461+
displayName: 'Bar',
462+
sortable: true
463+
},
464+
{
465+
attribute: 'theDefault',
466+
displayName: 'DefaultSort',
467+
sortable: true
468+
}
469+
];
470+
471+
const data = [
472+
{ title: 'foo', bar: 'a', theDefault: 3},
473+
{ title: 'sup', bar: 'c', theDefault: 2},
474+
{ title: 'yee', bar: 'b', theDefault: 1}
475+
];
476+
477+
ReactDOM.render(<Table columns={columns} data={data}/>, root);
478+
479+
expect('table').not.toHaveAttr('data');
480+
});
451481
});
452482

453483
describe('TableHeader', function() {

library/src/pivotal-ui-react/table/table.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,13 @@ export class Table extends React.Component {
115115

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

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

123123
return (
124-
<table {...props} >
124+
<table {...props}>
125125
<thead>
126126
<tr>{this.renderHeaders()}</tr>
127127
</thead>

0 commit comments

Comments
 (0)