Skip to content

Commit cf99c68

Browse files
author
August Toman-Yih
committed
[Fixed] In React.createElement, children can be passed in props
Previously, children could only be passed in as separate arguments to React.createElement Signed-off-by: Geoff Pleiss <gpleiss@pivotal.io>
1 parent 3b872fc commit cf99c68

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

lib/__tests__/index-test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,3 +706,31 @@ describe('warningPrefix', () => {
706706
});
707707
});
708708
});
709+
710+
describe('testing children', () => {
711+
var createElement = React.createElement;
712+
713+
before(() => {
714+
a11y(React, { exclude: ['REDUNDANT_ALT'] });
715+
});
716+
717+
after(() => {
718+
React.createElement = createElement;
719+
});
720+
721+
describe('when children is passed down in props', () => {
722+
it('calls each test with the children', () => {
723+
doNotExpectWarning(assertions.render.NO_LABEL.msg, () => {
724+
React.createElement('a', {href: 'google.com', children: 'Google'});
725+
});
726+
});
727+
});
728+
729+
describe('when children is passed down separately from props', () => {
730+
it('calls each test with the children', () => {
731+
doNotExpectWarning(assertions.render.NO_LABEL.msg, () => {
732+
React.createElement('a', {href: 'google.com'}, 'Google');
733+
});
734+
});
735+
});
736+
});

lib/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,11 @@ var reactA11y = (React, options) => {
177177
var props = _props || {};
178178
options = options || {};
179179

180+
if (children.length === 0) {
181+
children = props.children;
182+
delete props.children;
183+
}
184+
180185
props.id = createId(props);
181186
var reactEl = _createElement.apply(this, [type, props].concat(children));
182187
var failureCB = handleFailure.bind(undefined, options, reactEl);

0 commit comments

Comments
 (0)