Skip to content

Commit

Permalink
[fixed] Fix for bug507.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
AlexKVal committed Apr 21, 2015
1 parent 02b9c78 commit bc8cd5c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/Input.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,12 @@ const Input = React.createClass({
];
}

return <FormGroup {...this.props}>{children}</FormGroup>;
if (this.props.type === 'submit') {
let {bsStyle, ...other} = this.props; /* eslint no-unused-vars: 0 */
return <FormGroup {...other}>{children}</FormGroup>;
} else {
return <FormGroup {...this.props}>{children}</FormGroup>;
}
}
});

Expand Down
20 changes: 19 additions & 1 deletion test/InputSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('Input', function () {
assert.equal(instance.getValue(), 'v');
});

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

it('must not throw warning when bsStyle=danger and type=submit', function () {
ReactTestUtils.renderIntoDocument(
<Input type="submit" bsStyle="danger" />
);

console.warn.called.should.be.false;
});

it('throws warning about wrong type for bsStyle=error when type=submit', function () {
ReactTestUtils.renderIntoDocument(
<Input type="submit" bsStyle="error" />
);

console.warn.called.should.be.true;
console.warn.calledWithMatch('propType: Invalid').should.be.true;
console.warn.reset(); // reset state for afterEach()
});

it('renders a p element when type=static', function () {
let instance = ReactTestUtils.renderIntoDocument(
<Input type="static" value="v" />
Expand Down

0 comments on commit bc8cd5c

Please sign in to comment.