Skip to content

Commit

Permalink
Merge pull request #748 from CptLemming/support-column-subclasses
Browse files Browse the repository at this point in the history
Add support to Table to allow components that extend Column
  • Loading branch information
bvaughn authored Jul 20, 2017
2 parents 00f3903 + f8e2a88 commit 8bc2fa4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
12 changes: 12 additions & 0 deletions source/Table/Table.jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,18 @@ describe("Table", () => {
expect(result instanceof Error).toEqual(false);
});

it("should accept subclasses of Column as children", () => {
class AnotherColumn extends Column {}

const children = [<AnotherColumn dataKey="foo" width={100} />];
const result = Table.propTypes.children(
{ children },
"children",
"Table"
);
expect(result instanceof Error).toEqual(false);
});

it("should not accept non-Column children", () => {
const children = [<div />];
const result = Table.propTypes.children(
Expand Down
3 changes: 2 additions & 1 deletion source/Table/Table.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export default class Table extends PureComponent {
children: props => {
const children = React.Children.toArray(props.children);
for (let i = 0; i < children.length; i++) {
if (children[i].type !== Column) {
const childType = children[i].type;
if (childType !== Column && !(childType.prototype instanceof Column)) {
return new Error("Table only accepts children of type Column");
}
}
Expand Down

0 comments on commit 8bc2fa4

Please sign in to comment.