Skip to content

Commit

Permalink
fix: support React 16 fragments
Browse files Browse the repository at this point in the history
Resolves #127.
  • Loading branch information
jessepinho committed Nov 14, 2017
1 parent 710c47d commit 36f8372
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion dist/react-responsive.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/react-responsive.js.map

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion dist/react-responsive.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/react-responsive.min.js.map

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,7 @@ class MediaQuery extends React.Component {
const hasMergeProps = Object.keys(props).length > 0
const childrenCount = React.Children.count(this.props.children)
const wrapChildren = this.props.component ||
childrenCount > 1 ||
typeof this.props.children === 'string' ||
Array.isArray(this.props.children) && childrenCount == 1 ||
this.props.children === undefined
if (wrapChildren) {
return React.createElement(
Expand Down
9 changes: 5 additions & 4 deletions test/index_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,24 +54,25 @@ describe('MediaQuery', function () {
const e = TestUtils.renderIntoDocument(mq)
assert.isNotFalse(TestUtils.findRenderedDOMComponentWithTag(e, 'section'))
})
it('renders a div when theres multiple children', function () {
it('does not render a div when there are multiple children', function () {
const mq = (
<MediaQuery query="all">
<span className="childComponent"/>
<span className="childComponent"/>
</MediaQuery>
)
const e = TestUtils.renderIntoDocument(mq)
assert.isNotFalse(TestUtils.findRenderedDOMComponentWithTag(e, 'div'))
assert.throws(() => (TestUtils.findRenderedDOMComponentWithTag(e, 'div')), /Did not find exactly one match/)
})
it('renders a div when children is a single-element array', function () {
it('renders the first child when children is a single-element array', function () {
const mq = (
<MediaQuery query="all">
{[ 'single element' ].map((content, index) => <span key={index}>{content}</span>)}
</MediaQuery>
)
const e = TestUtils.renderIntoDocument(mq)
assert.isNotFalse(TestUtils.findRenderedDOMComponentWithTag(e, 'div'))
assert.isNotFalse(TestUtils.findRenderedDOMComponentWithTag(e, 'span'))
assert.throws(() => (TestUtils.findRenderedDOMComponentWithTag(e, 'div')), /Did not find exactly one match/)
})
it('passes extra props', function () {
const mq = (
Expand Down

0 comments on commit 36f8372

Please sign in to comment.