Skip to content

Commit bbe33f9

Browse files
committed
allow custom child elements
also add a comment for anyone unfamiliar with the input style
1 parent 27435a3 commit bbe33f9

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

lib/index.js

+17-12
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ var FileInput = React.createClass({
88
parent: {
99
position: 'relative'
1010
},
11+
// "invisible" above the text
1112
file: {
1213
position: 'absolute',
1314
top: 0,
@@ -32,6 +33,21 @@ var FileInput = React.createClass({
3233
},
3334

3435
render: function() {
36+
// Emulated file input for when there are no children
37+
var emulatedInput = React.DOM.input({
38+
type: 'text',
39+
tabIndex: -1,
40+
name: this.props.name + '_filename',
41+
value: this.state.value,
42+
className: this.props.className,
43+
onChange: function() {},
44+
placeholder: this.props.placeholder,
45+
disabled: this.props.disabled,
46+
style: this.state.styles.text
47+
});
48+
49+
var child = this.props.children ? this.props.children : emulatedInput;
50+
3551
return React.DOM.div({
3652
style: this.state.styles.parent
3753
},
@@ -47,18 +63,7 @@ var FileInput = React.createClass({
4763
style: this.state.styles.file
4864
}),
4965

50-
// Emulated file input
51-
React.DOM.input({
52-
type: 'text',
53-
tabIndex: -1,
54-
name: this.props.name + '_filename',
55-
value: this.state.value,
56-
className: this.props.className,
57-
onChange: function() {},
58-
placeholder: this.props.placeholder,
59-
disabled: this.props.disabled,
60-
style: this.state.styles.text
61-
}));
66+
child);
6267
}
6368
});
6469

0 commit comments

Comments
 (0)