Skip to content

Commit

Permalink
[fixed] proper element text node traversal
Browse files Browse the repository at this point in the history
  • Loading branch information
jquense committed Oct 10, 2015
1 parent d71b7c1 commit 0e3d7d1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
7 changes: 6 additions & 1 deletion lib/instance-selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@ function findAll(inst, test, includeSelf) {

if (isDOMComponent(publicInst)) {
(function () {
var renderedChildren = inst._renderedChildren || {};
var renderedChildren = inst._renderedChildren || {},
child = inst._currentElement.props.children;

if (typeof child === 'string' && test(child, null, parent)) {
found = found.concat(child);
}

Object.keys(renderedChildren).forEach(function (key) {
found = found.concat(findAll(renderedChildren[key], test, true, parent));
Expand Down
2 changes: 1 addition & 1 deletion lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bill",
"version": "1.3.0",
"version": "1.3.1",
"description": "css selectors for React Elements",
"main": "index.js",
"repository": {
Expand Down
8 changes: 1 addition & 7 deletions src/element-selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,7 @@ export function findAll(root, test, includeSelf, getParent = ()=> ({ parent: nul

React.Children.forEach(children, child => {
let parent = ()=> ({ parent: root, getParent });

if (React.isValidElement(child)){
if (test(child, parent))
found.push(child);

found = found.concat(findAll(child, test, false, parent))
}
found = found.concat(findAll(child, test, true, parent))
})

return found
Expand Down

0 comments on commit 0e3d7d1

Please sign in to comment.