From 83cdaa3ffeb8453d0c3c4b721335cf0442986970 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Lign=C3=A9?= Date: Mon, 10 Aug 2015 17:04:01 +0200 Subject: [PATCH] [added] formControlFeedback prop to Glyphicon Less typing when passing a `Glyphicon` as feedbackIcon into an `Input`. --- src/Glyphicon.js | 7 +++++-- test/GlyphiconSpec.js | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/Glyphicon.js b/src/Glyphicon.js index e406feaa31..9f5a2d69ad 100644 --- a/src/Glyphicon.js +++ b/src/Glyphicon.js @@ -7,12 +7,14 @@ 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 }; }, @@ -20,6 +22,7 @@ const Glyphicon = React.createClass({ let classes = this.getBsClassSet(); classes['glyphicon-' + this.props.glyph] = true; + classes['form-control-feedback'] = this.props.formControlFeedback; return ( diff --git a/test/GlyphiconSpec.js b/test/GlyphiconSpec.js index fec68f5c1d..49d8338436 100644 --- a/test/GlyphiconSpec.js +++ b/test/GlyphiconSpec.js @@ -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( + + ); + + 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( + + ); + + assert.ok(React.findDOMNode(instance).className.match(/\bform-control-feedback\b/)); + }); + }); });