forked from react-bootstrap/react-bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[added]
standalone
prop to Input, which will not render the `form-g…
…roup` class In some cases you may not want the `form-group` class applied to form input wrapper divs. To achieve this simply apply the `standalone` prop. Fixes react-bootstrap#205
- Loading branch information
Showing
5 changed files
with
159 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import React from 'react'; | ||
import classSet from 'classnames'; | ||
|
||
class FormGroup extends React.Component { | ||
render() { | ||
let classes = { | ||
'form-group': !this.props.standalone, | ||
'has-feedback': this.props.hasFeedback, | ||
'has-success': this.props.bsStyle === 'success', | ||
'has-warning': this.props.bsStyle === 'warning', | ||
'has-error': this.props.bsStyle === 'error' | ||
}; | ||
|
||
return ( | ||
<div className={classSet(classes, this.props.groupClassName)}> | ||
{this.props.children} | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
FormGroup.defaultProps = { | ||
standalone: false | ||
}; | ||
|
||
FormGroup.propTypes = { | ||
standalone: React.PropTypes.bool, | ||
hasFeedback: React.PropTypes.bool, | ||
bsStyle: React.PropTypes.oneOf(['success', 'warning', 'error']), | ||
groupClassName: React.PropTypes.string | ||
}; | ||
|
||
export default FormGroup; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import React from 'react'; | ||
import ReactTestUtils from 'react/lib/ReactTestUtils'; | ||
import FormGroup from '../src/FormGroup'; | ||
|
||
describe('FormGroup', function() { | ||
beforeEach(function() { | ||
sinon.spy(console, 'warn'); | ||
}); | ||
|
||
afterEach(function() { | ||
if (typeof console.warn.restore === 'function') { | ||
console.warn.called.should.be.false; | ||
console.warn.restore(); | ||
} | ||
}); | ||
|
||
it('renders children', function() { | ||
let instance = ReactTestUtils.renderIntoDocument( | ||
<FormGroup> | ||
<span className='child1' /> | ||
<span className='child2' /> | ||
</FormGroup> | ||
); | ||
|
||
assert.ok(ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'child1')); | ||
assert.ok(ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'child2')); | ||
}); | ||
|
||
it('renders with form-group class', function() { | ||
let instance = ReactTestUtils.renderIntoDocument( | ||
<FormGroup> | ||
<span /> | ||
</FormGroup> | ||
); | ||
|
||
assert.ok(ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'form-group')); | ||
}); | ||
|
||
it('renders no form-group class when standalone', function() { | ||
let instance = ReactTestUtils.renderIntoDocument( | ||
<FormGroup standalone> | ||
<span /> | ||
</FormGroup> | ||
); | ||
|
||
assert.equal(ReactTestUtils.scryRenderedDOMComponentsWithClass(instance, 'form-group').length, 0); | ||
}); | ||
|
||
[{ | ||
className: 'has-feedback', | ||
props: { hasFeedback: true } | ||
}, { | ||
className: 'has-success', | ||
props: { bsStyle: 'success' } | ||
}, { | ||
className: 'has-warning', | ||
props: { bsStyle: 'warning' } | ||
}, { | ||
className: 'has-error', | ||
props: { bsStyle: 'error' } | ||
}, { | ||
className: 'custom-group', | ||
props: { groupClassName: 'custom-group' } | ||
} | ||
].forEach(function(testCase) { | ||
it(`does not render ${testCase.className} class`, function() { | ||
let instance = ReactTestUtils.renderIntoDocument( | ||
<FormGroup> | ||
<span /> | ||
</FormGroup> | ||
); | ||
|
||
assert.equal(ReactTestUtils.scryRenderedDOMComponentsWithClass(instance, testCase.className).length, 0); | ||
}); | ||
|
||
it(`renders with ${testCase.className} class`, function() { | ||
let instance = ReactTestUtils.renderIntoDocument( | ||
<FormGroup {...testCase.props}> | ||
<span /> | ||
</FormGroup> | ||
); | ||
|
||
assert.ok(ReactTestUtils.findRenderedDOMComponentWithClass(instance, testCase.className)); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters