Skip to content

Commit

Permalink
feat(FormFeedback): Support valid feedback. (#840)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Eriksson authored and TheSharpieOne committed Feb 15, 2018
1 parent 2495154 commit 9b49091
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/lib/examples/FormFeedback.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default class Example extends React.Component {
<FormGroup>
<Label for="exampleEmail">Input with success</Label>
<Input valid />
<FormFeedback valid>Oh noes! that name is already taken</FormFeedback>
<FormText>Example help text that remains unchanged.</FormText>
</FormGroup>
<FormGroup>
Expand Down
5 changes: 4 additions & 1 deletion src/FormFeedback.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,26 @@ const propTypes = {
tag: PropTypes.string,
className: PropTypes.string,
cssModule: PropTypes.object,
valid: PropTypes.bool
};

const defaultProps = {
tag: 'div',
valid: undefined
};

const FormFeedback = (props) => {
const {
className,
cssModule,
valid,
tag: Tag,
...attributes
} = props;

const classes = mapToCssModules(classNames(
className,
'invalid-feedback'
valid ? 'valid-feedback' : 'invalid-feedback'
), cssModule);

return (
Expand Down
6 changes: 6 additions & 0 deletions src/__tests__/FormFeedback.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ describe('FormFeedback', () => {
expect(wrapper.hasClass('invalid-feedback')).toBe(true);
});

it('should render with "valid-feedback" class', () => {
const wrapper = shallow(<FormFeedback valid>Yo!</FormFeedback>);

expect(wrapper.hasClass('valid-feedback')).toBe(true);
});

it('should render additional classes', () => {
const wrapper = shallow(<FormFeedback className="other">Yo!</FormFeedback>);

Expand Down

0 comments on commit 9b49091

Please sign in to comment.