Skip to content

Commit 716afd5

Browse files
committed
Single ReactElement not an array.
1 parent fb3272f commit 716afd5

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

dist/linkClass.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,7 @@ linkClass = function (element, styles, userConfiguration) {
6767
appendClassName = appendClassName.join(' ');
6868
}
6969

70-
// A child can be either an array, a sole object or a string.
71-
// <div>test</div>
72-
if (_utils2['default'].isArray(element.props.children)) {
70+
if (_utils2['default'].isArray(element.props.children) || _react2['default'].isValidElement(element.props.children)) {
7371
childrenCount = _react2['default'].Children.count(element.props.children);
7472

7573
// console.log('childrenCount', childrenCount, 'element.props.children', element.props.children);

src/linkClass.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ linkClass = (element, styles = {}, userConfiguration) => {
4949
appendClassName = appendClassName.join(' ');
5050
}
5151

52-
// A child can be either an array, a sole object or a string.
53-
// <div>test</div>
54-
if (_.isArray(element.props.children)) {
52+
if (_.isArray(element.props.children) || React.isValidElement(element.props.children)) {
5553
childrenCount = React.Children.count(element.props.children);
5654

5755
// console.log('childrenCount', childrenCount, 'element.props.children', element.props.children);

test/linkClass.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,39 @@ describe('linkClass', () => {
6363
});
6464

6565
context('when styleName matches an existing CSS module', () => {
66+
context('when a descendant element has styleName', () => {
67+
it('assigns a generated className', () => {
68+
let subject;
69+
70+
subject = <div>
71+
<p styleName='foo'></p>
72+
</div>;
73+
74+
subject = linkClass(subject, {
75+
foo: 'foo-1'
76+
});
77+
78+
expect(subject.props.children.props.className).to.equal('foo-1');
79+
});
80+
});
81+
context('when multiple descendant elements have styleName', () => {
82+
it('assigns a generated className', () => {
83+
let subject;
84+
85+
subject = <div>
86+
<p styleName='foo'></p>
87+
<p styleName='bar'></p>
88+
</div>;
89+
90+
subject = linkClass(subject, {
91+
foo: 'foo-1',
92+
bar: 'bar-1'
93+
});
94+
95+
expect(subject.props.children['.0'].props.className).to.equal('foo-1');
96+
expect(subject.props.children['.1'].props.className).to.equal('bar-1');
97+
});
98+
});
6699
context('when ReactElement does not have an existing className', () => {
67100
it('uses the generated class name to set the className property', () => {
68101
let subject;

0 commit comments

Comments
 (0)