From 255ee0bd1415e7f137ed229db0f5a61310074579 Mon Sep 17 00:00:00 2001 From: "vitalii.mazurenko" Date: Wed, 22 Aug 2018 13:37:58 +0300 Subject: [PATCH] Fix assign a generated className to elements inside nested arrays --- src/linkClass.js | 9 +-------- tests/linkClass.js | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/linkClass.js b/src/linkClass.js index 73783b4..d296742 100644 --- a/src/linkClass.js +++ b/src/linkClass.js @@ -50,14 +50,7 @@ const linkElement = (element: ReactElement, styles: Object, configuration: Objec if (React.isValidElement(children)) { elementShallowCopy.props.children = linkElement(React.Children.only(children), styles, configuration); } else if (_.isArray(children) || isIterable(children)) { - elementShallowCopy.props.children = _.map(children, (node) => { - if (React.isValidElement(node)) { - // eslint-disable-next-line no-use-before-define - return linkElement(React.Children.only(node), styles, configuration); - } else { - return node; - } - }); + elementShallowCopy.props.children = linkArray(objectUnfreeze(children), styles, configuration); } _.forEach(restProps, (propValue, propName) => { diff --git a/tests/linkClass.js b/tests/linkClass.js index 90a66b2..cf7c289 100644 --- a/tests/linkClass.js +++ b/tests/linkClass.js @@ -125,6 +125,33 @@ describe('linkClass', () => { expect(subject.props.children[0].props.className).to.equal('foo-1'); expect(subject.props.children[1].props.className).to.equal('bar-1'); }); + it('assigns a generated className to elements inside nested arrays', () => { + let subject; + + subject =
+ {[ + [ +

, +

+ ], + [ +

, +

+ ] + ]} +

; + + subject = linkClass(subject, { + bar: 'bar-1', + foo: 'foo-1' + }); + + expect(subject.props.children[0][0].props.className).to.equal('foo-1'); + expect(subject.props.children[0][1].props.className).to.equal('bar-1'); + + expect(subject.props.children[1][0].props.className).to.equal('foo-1'); + expect(subject.props.children[1][1].props.className).to.equal('bar-1'); + }); it('styleName is deleted from props', () => { let subject;