Skip to content

Commit 4cd5845

Browse files
committed
[added] FormGroup/Input bsSize now propgates correctly as form-group-\* classes
1 parent 3068158 commit 4cd5845

File tree

5 files changed

+38
-1
lines changed

5 files changed

+38
-1
lines changed

docs/examples/InputSizes.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const inputSizeInstance = (
2+
<form>
3+
<Input type='text' bsSize="large" placeholder='Large text' />
4+
<Input type='text' bsSize="medium" placeholder='Normal text' />
5+
<Input type='text' bsSize="small" placeholder='Small text' />
6+
</form>
7+
);
8+
9+
React.render(inputSizeInstance, mountNode);

docs/src/ComponentsPage.js

+3
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,9 @@ const ComponentsPage = React.createClass({
561561
<p>Use <code>addonBefore</code> and <code>addonAfter</code> for normal addons, <code>buttonBefore</code> and <code>buttonAfter</code> for button addons.
562562
Exotic configurations may require some css on your side.</p>
563563
<ReactPlayground codeText={Samples.InputAddons} />
564+
<h2 id='input-sizes'>Sizes</h2>
565+
<p>Use <code>bsSize</code> to change the size of inputs. It also works with addons and most other options.</p>
566+
<ReactPlayground codeText={Samples.InputSizes} />
564567
<h2 id='input-validation'>Validation</h2>
565568
<p>Set <code>bsStyle</code> to one of <code>success</code>, <code>warning</code> or <code>error</code>.
566569
Add <code>hasFeedback</code> to show glyphicon. Glyphicon may need additional styling if there is an add-on or no label.</p>

docs/src/Samples.js

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ export default {
8484
Input: require('fs').readFileSync(__dirname + '/../examples/Input.js', 'utf8'),
8585
InputTypes: require('fs').readFileSync(__dirname + '/../examples/InputTypes.js', 'utf8'),
8686
InputAddons: require('fs').readFileSync(__dirname + '/../examples/InputAddons.js', 'utf8'),
87+
InputSizes: require('fs').readFileSync(__dirname + '/../examples/InputSizes.js', 'utf8'),
8788
InputValidation: require('fs').readFileSync(__dirname + '/../examples/InputValidation.js', 'utf8'),
8889
InputHorizontal: require('fs').readFileSync(__dirname + '/../examples/InputHorizontal.js', 'utf8'),
8990
InputWrapper: require('fs').readFileSync(__dirname + '/../examples/InputWrapper.js', 'utf8')

src/FormGroup.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@ FormGroup.defaultProps = {
2828
FormGroup.propTypes = {
2929
standalone: React.PropTypes.bool,
3030
hasFeedback: React.PropTypes.bool,
31-
bsSize: React.PropTypes.oneOf(['small', 'medium', 'large']),
31+
bsSize (props) {
32+
if (props.standalone) {
33+
return new Error('bsSize will not be used when `standalone` is set.');
34+
}
35+
36+
return React.PropTypes.oneOf(['small', 'medium', 'large']).apply(null, arguments);
37+
},
3238
bsStyle: React.PropTypes.oneOf(['success', 'warning', 'error']),
3339
groupClassName: React.PropTypes.string
3440
};

test/FormGroupSpec.js

+18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import ReactTestUtils from 'react/lib/ReactTestUtils';
33
import FormGroup from '../src/FormGroup';
4+
import {shouldWarn} from './helpers';
45

56
describe('FormGroup', function() {
67
it('renders children', function() {
@@ -45,6 +46,14 @@ describe('FormGroup', function() {
4546
assert.ok(ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'form-group-lg'));
4647
});
4748

49+
it('throws warning about bsSize when standalone', function () {
50+
ReactTestUtils.renderIntoDocument(
51+
<FormGroup standalone bsSize="large" />
52+
);
53+
54+
shouldWarn('Failed propType: bsSize');
55+
});
56+
4857
it('renders no form-group class when standalone', function() {
4958
let instance = ReactTestUtils.renderIntoDocument(
5059
<FormGroup standalone>
@@ -55,6 +64,15 @@ describe('FormGroup', function() {
5564
assert.equal(ReactTestUtils.scryRenderedDOMComponentsWithClass(instance, 'form-group').length, 0);
5665
});
5766

67+
it('renders no form-group-* class when standalone', function () {
68+
let instance = ReactTestUtils.renderIntoDocument(
69+
<FormGroup standalone bsSize="large" />
70+
);
71+
72+
assert.equal(ReactTestUtils.scryRenderedDOMComponentsWithClass(instance, 'form-group').length, 0);
73+
assert.equal(ReactTestUtils.scryRenderedDOMComponentsWithClass(instance, 'form-group-lg').length, 0);
74+
});
75+
5876
[{
5977
className: 'has-feedback',
6078
props: { hasFeedback: true }

0 commit comments

Comments
 (0)