Skip to content

Commit cc12453

Browse files
author
Zach Silveira
authored
Add the recursive index too
1 parent 244d828 commit cc12453

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

form.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@ export default class Form extends React.Component {
77
this.inputs = [];
88
}
99

10-
renderChildren(children) {
10+
renderChildren(children, recursiveIndex = 0) {
1111
return React.Children.map(children, (child, index) => {
1212
if (child.props.children)
1313
return React.cloneElement(child, {
1414
...child.props,
15-
children: this.renderChildren(child.props.children)
15+
children: this.renderChildren(child.props.children, index)
1616
});
1717
if (child.type.name !== 'TextInput') return child;
1818

1919
return React.cloneElement(child, {
2020
onEnter: () =>
21-
this.inputs[index + 1] ? this.inputs[index + 1].focus() : null,
21+
this.inputs[index + recursiveIndex + 1] ? this.inputs[index + recursiveIndex + 1].focus() : null,
2222
inputRef: ref => (this.inputs[index] = ref),
2323
});
2424
});

0 commit comments

Comments
 (0)