Skip to content

Commit

Permalink
[added] formControlFeedback prop to Glyphicon
Browse files Browse the repository at this point in the history
Less typing when passing a `Glyphicon` as
feedbackIcon into an `Input`.
  • Loading branch information
André Ligné committed Aug 10, 2015
1 parent 4f1fd83 commit 83cdaa3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Glyphicon.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,22 @@ const Glyphicon = React.createClass({
mixins: [BootstrapMixin],

propTypes: {
glyph: React.PropTypes.oneOf(styleMaps.GLYPHS).isRequired
glyph: React.PropTypes.oneOf(styleMaps.GLYPHS).isRequired,
formControlFeedback: React.PropTypes.bool
},

getDefaultProps() {
return {
bsClass: 'glyphicon'
bsClass: 'glyphicon',
formControlFeedback: false
};
},

render() {
let classes = this.getBsClassSet();

classes['glyphicon-' + this.props.glyph] = true;
classes['form-control-feedback'] = this.props.formControlFeedback;

return (
<span {...this.props} className={classNames(this.props.className, classes)}>
Expand Down
18 changes: 18 additions & 0 deletions test/GlyphiconSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,22 @@ describe('Glyphicon', function () {
assert.ok(React.findDOMNode(instance).className.match(/\bglyphicon\b/));
assert.ok(React.findDOMNode(instance).className.match(/\bglyphicon-star\b/));
});

it('renders without the .form-control-feedback class', function () {
let instance = ReactTestUtils.renderIntoDocument(
<Glyphicon glyph='star' />
);

assert.notOk(React.findDOMNode(instance).className.match(/\bform-control-feedback\b/));
});

context('when setting the formControlFeedback prop', function () {
it('should have the .form-control-feedback class set', function () {
let instance = ReactTestUtils.renderIntoDocument(
<Glyphicon formControlFeedback glyph='star' />
);

assert.ok(React.findDOMNode(instance).className.match(/\bform-control-feedback\b/));
});
});
});

0 comments on commit 83cdaa3

Please sign in to comment.