Skip to content

Commit bc8cd5c

Browse files
committed
[fixed] Fix for bug507.
In the case when `<Input />` type is `submit`, bootstrap style set in `bsStyle` property goes down to inner `<Button />` conponent. Consequently default bootstrap styles for `<Button />` are not suited for `<FormGroup />` component that is the root element for `<Input />` component. Therefore in that case we just need to prevent `bsStyle` passing on to <FormGroup />. Tests added and temporarily suspended test is unskipped.
1 parent 02b9c78 commit bc8cd5c

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

Diff for: src/Input.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,12 @@ const Input = React.createClass({
245245
];
246246
}
247247

248-
return <FormGroup {...this.props}>{children}</FormGroup>;
248+
if (this.props.type === 'submit') {
249+
let {bsStyle, ...other} = this.props; /* eslint no-unused-vars: 0 */
250+
return <FormGroup {...other}>{children}</FormGroup>;
251+
} else {
252+
return <FormGroup {...this.props}>{children}</FormGroup>;
253+
}
249254
}
250255
});
251256

Diff for: test/InputSpec.js

+19-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ describe('Input', function () {
4040
assert.equal(instance.getValue(), 'v');
4141
});
4242

43-
it.skip('renders a submit button element when type=submit', function () {
43+
it('renders a submit button element when type=submit', function () {
4444
let instance = ReactTestUtils.renderIntoDocument(
4545
<Input type="submit" bsStyle="danger" wrapperClassName='test' />
4646
);
@@ -50,6 +50,24 @@ describe('Input', function () {
5050
assert.equal(node.getAttribute('class'), 'btn btn-danger');
5151
});
5252

53+
it('must not throw warning when bsStyle=danger and type=submit', function () {
54+
ReactTestUtils.renderIntoDocument(
55+
<Input type="submit" bsStyle="danger" />
56+
);
57+
58+
console.warn.called.should.be.false;
59+
});
60+
61+
it('throws warning about wrong type for bsStyle=error when type=submit', function () {
62+
ReactTestUtils.renderIntoDocument(
63+
<Input type="submit" bsStyle="error" />
64+
);
65+
66+
console.warn.called.should.be.true;
67+
console.warn.calledWithMatch('propType: Invalid').should.be.true;
68+
console.warn.reset(); // reset state for afterEach()
69+
});
70+
5371
it('renders a p element when type=static', function () {
5472
let instance = ReactTestUtils.renderIntoDocument(
5573
<Input type="static" value="v" />

0 commit comments

Comments
 (0)