Skip to content

Commit 71ff264

Browse files
author
Matthew Scott
committedMar 3, 2015
[added] bsSize prop to Input, supporting input groups
This allows for specifying a size, such as 'small' or 'large', such as: <Input type="text" placeholder="Search" bsSize="small" buttonAfter={<Button><Glyphicon glyph="search" /></Button>} /> (Input groups are enabled whenever these props have values: addonBefore, addonAfter, buttonBefore, or buttonAfter) This maps to the "input-group-sm" and "input-group-lg" classes as documented here: http://getbootstrap.com/components/#input-groups-sizing
1 parent 35d39ba commit 71ff264

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed
 

‎src/Input.jsx

+9-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var classSet = require('./utils/classSet');
44
var Button = require('./Button');
55

66
var Input = React.createClass({
7+
78
propTypes: {
89
type: React.PropTypes.string,
910
label: React.PropTypes.node,
@@ -12,6 +13,7 @@ var Input = React.createClass({
1213
addonAfter: React.PropTypes.node,
1314
buttonBefore: React.PropTypes.node,
1415
buttonAfter: React.PropTypes.node,
16+
bsSize: React.PropTypes.oneOf(['small', 'medium', 'large']),
1517
bsStyle: function(props) {
1618
if (props.type === 'submit') {
1719
// Return early if `type=submit` as the `Button` component
@@ -140,8 +142,14 @@ var Input = React.createClass({
140142
</span>
141143
) : null;
142144

145+
var inputGroupClassName;
146+
switch (this.props.bsSize) {
147+
case 'small': inputGroupClassName = 'input-group-sm'; break;
148+
case 'large': inputGroupClassName = 'input-group-lg'; break;
149+
}
150+
143151
return addonBefore || addonAfter || buttonBefore || buttonAfter ? (
144-
<div className="input-group" key="input-group">
152+
<div className={joinClasses(inputGroupClassName, 'input-group')} key="input-group">
145153
{addonBefore}
146154
{buttonBefore}
147155
{children}

‎test/InputSpec.jsx

+16
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,22 @@ describe('Input', function () {
123123
assert.ok(ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'input-group-addon'));
124124
});
125125

126+
it('renders input-group with sm or lg class name when bsSize is small or large', function () {
127+
var instance = ReactTestUtils.renderIntoDocument(
128+
<Input addonBefore="$" bsSize="small" />
129+
);
130+
131+
assert.ok(ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'input-group'));
132+
assert.ok(ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'input-group-sm'));
133+
134+
instance = ReactTestUtils.renderIntoDocument(
135+
<Input addonBefore="$" bsSize="large" />
136+
);
137+
138+
assert.ok(ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'input-group'));
139+
assert.ok(ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'input-group-lg'));
140+
});
141+
126142
it('renders btn-group', function() {
127143
var instance = ReactTestUtils.renderIntoDocument(
128144
<Input buttonAfter={<Button>!</Button>} />

0 commit comments

Comments
 (0)
Please sign in to comment.