Skip to content

Commit ecd8c6a

Browse files
committed
Merge pull request react-bootstrap#274 from trentgrover-wf/fileInput
File input is incorrectly wrapped in a border box
2 parents ad8309b + 4a6fd25 commit ecd8c6a

3 files changed

Lines changed: 31 additions & 10 deletions

File tree

docs/examples/InputTypes.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,23 @@
22

33
var inputTypeInstance = (
44
<form>
5-
<Input type="text" defaultValue="text" />
6-
<Input type="password" defaultValue="secret" />
7-
<Input type="checkbox" checked readOnly label="checkbox"/>
8-
<Input type="radio" checked readOnly label="radio"/>
9-
<Input type="select" defaultValue="select">
5+
<Input type="text" label='Text' defaultValue="Enter text" />
6+
<Input type="email" label='Email Address' defaultValue="Enter email" />
7+
<Input type="password" label='Password' defaultValue="secret" />
8+
<Input type="file" label="File" help="[Optional] Block level help text" />
9+
<Input type="checkbox" label="Checkbox" checked readOnly />
10+
<Input type="radio" label="Radio" checked readOnly />
11+
<Input type="select" label='Select' defaultValue="select">
1012
<option value="select">select</option>
1113
<option value="other">...</option>
1214
</Input>
13-
<Input type="select" multiple>
15+
<Input type="select" label='Multiple Select' multiple>
1416
<option value="select">select (multiple)</option>
1517
<option value="other">...</option>
1618
</Input>
17-
<Input type="textarea" defaultValue="textarea" />
18-
<Input type="static" value="static" />
19-
<Input type="submit" bsStyle='primary' value="Submit button" />
19+
<Input type="textarea" label='Text Area' defaultValue="textarea" />
20+
<Input type="static" value="Static Text" />
21+
<Input type="submit" value="Submit button" />
2022
</form>
2123
);
2224

src/Input.jsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ var Input = React.createClass({
5151
return this.props.type === 'radio' || this.props.type === 'checkbox';
5252
},
5353

54+
isFile: function () {
55+
return this.props.type === 'file';
56+
},
57+
5458
renderInput: function () {
5559
var input = null;
5660

@@ -82,7 +86,7 @@ var Input = React.createClass({
8286
);
8387
break;
8488
default:
85-
var className = this.isCheckboxOrRadio() ? '' : 'form-control';
89+
var className = this.isCheckboxOrRadio() || this.isFile() ? '' : 'form-control';
8690
input = <input className={className} ref="input" key="input" />;
8791
}
8892

test/InputSpec.jsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,21 @@ describe('Input', function () {
137137
assert.ok(ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'form-control-feedback'));
138138
});
139139

140+
it('renders file correctly', function () {
141+
var instance = ReactTestUtils.renderIntoDocument(
142+
<Input type="file" wrapperClassName="wrapper" label="Label" help="h" />
143+
);
144+
145+
var node = instance.getDOMNode();
146+
assert.include(node.className, 'form-group');
147+
assert.equal(node.children[0].tagName.toLowerCase(), 'label');
148+
assert.include(node.children[1].className, 'wrapper');
149+
assert.equal(node.children[1].children[0].tagName.toLowerCase(), 'input');
150+
assert.equal(node.children[1].children[0].className, '');
151+
assert.equal(node.children[1].children[0].type, 'file');
152+
assert.equal(node.children[1].children[1].className, 'help-block');
153+
});
154+
140155
it('renders checkbox/radio correctly', function () {
141156
var instance = ReactTestUtils.renderIntoDocument(
142157
<Input type="checkbox" wrapperClassName="wrapper" label="Label" help="h" />

0 commit comments

Comments
 (0)