From f8e2a88bf33f91b2f8932c10a10e335f762e945e Mon Sep 17 00:00:00 2001 From: Ashley Wilson Date: Wed, 19 Jul 2017 09:53:13 +0100 Subject: [PATCH] Add support to Table to allow components that extend Column --- source/Table/Table.jest.js | 12 ++++++++++++ source/Table/Table.js | 3 ++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/source/Table/Table.jest.js b/source/Table/Table.jest.js index f596ea525..e34477852 100644 --- a/source/Table/Table.jest.js +++ b/source/Table/Table.jest.js @@ -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 = []; + const result = Table.propTypes.children( + { children }, + "children", + "Table" + ); + expect(result instanceof Error).toEqual(false); + }); + it("should not accept non-Column children", () => { const children = [
]; const result = Table.propTypes.children( diff --git a/source/Table/Table.js b/source/Table/Table.js index c9d16b2ac..8034f8217 100644 --- a/source/Table/Table.js +++ b/source/Table/Table.js @@ -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"); } }