Skip to content

Restore prefixing of react children keys. Fixes #245 #246

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
Jul 5, 2017
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
16 changes: 1 addition & 15 deletions src/linkClass.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,6 @@ import isIterable from './isIterable';
import parseStyleName from './parseStyleName';
import generateAppendClassName from './generateAppendClassName';

const mapChildrenWithoutKeyPrefix = (children: ReactElement, mapper: Function, context: Object) => {
if (typeof children === 'undefined' || children === null) {
return children;
}

const result = [];

React.Children.forEach(children, (child, index) => {
result.push(mapper.call(context, child, index));
});

return result;
};

const linkArray = (array: Array, styles: Object, configuration: Object) => {
_.forEach(array, (value, index) => {
if (React.isValidElement(value)) {
Expand Down Expand Up @@ -55,7 +41,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 = mapChildrenWithoutKeyPrefix(children, (node) => {
elementShallowCopy.props.children = React.Children.map(children, (node) => {
if (React.isValidElement(node)) {
// eslint-disable-next-line no-use-before-define
return linkElement(React.Children.only(node), styles, configuration);
Expand Down
16 changes: 0 additions & 16 deletions tests/linkClass.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,20 +351,4 @@ describe('linkClass', () => {
expect(subject.props.els[1][0].props.className).to.deep.equal('bar-1');
expect(subject.props.els[1][0].props).not.to.have.property('styleName');
});

it('does not change defined keys of children if there are multiple children', () => {
let subject;

subject = <div els={[<span key='foo' />, <span key='bar' />]}>
<span key='foo' />
<span key='bar' />
</div>;

subject = linkClass(subject);

expect(subject.props.children[0].key).to.equal('foo');
expect(subject.props.children[1].key).to.equal('bar');
expect(subject.props.els[0].key).to.equal('foo');
expect(subject.props.els[1].key).to.equal('bar');
});
});