Skip to content

Fix assign a generated className to elements inside nested arrays #292

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions src/linkClass.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
27 changes: 27 additions & 0 deletions tests/linkClass.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <div>
{[
[
<p key='1' styleName='foo' />,
<p key='2' styleName='bar' />
],
[
<p key='1' styleName='foo' />,
<p key='2' styleName='bar' />
]
]}
</div>;

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;

Expand Down