Skip to content

Commit

Permalink
input does not render label if it does not exist
Browse files Browse the repository at this point in the history
Signed-off-by: Yucheng Tu <ytu@pivotal.io>
  • Loading branch information
nomel7 authored and Yucheng Tu committed Mar 17, 2016
1 parent 0f30674 commit 7369043
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions library/spec/pivotal-ui-react/inputs/inputs_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ describe('Input', function() {
expect('.form-group').toHaveClass('input-class');
});

describe('when label is undefined', () => {
beforeEach(() => {
subject::setProps({label: undefined});
});

it('does not render label', () => {
expect('label').not.toExist();
});
});

describe('Validation', function() {
it('does not show error messages when displayError is false', function() {
expect('.error-text').not.toExist();
Expand Down
2 changes: 1 addition & 1 deletion library/src/pivotal-ui-react/inputs/inputs.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Input extends React.Component {
const inputProps = mergeProps(props, {className: inputClassNames, 'aria-label': placeholder})
return (
<div className={formClasses}>
<label htmlFor={id} className={labelClasses}>{label}</label>
{label && <label htmlFor={id} className={labelClasses}>{label}</label>}
<input {...inputProps} />
{search && <i className='search-icon'/>}
{displayError && <div className="error-text help-block">
Expand Down

1 comment on commit 7369043

@Pirolf
Copy link

@Pirolf Pirolf commented on 7369043 Mar 17, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optionally render label

Please sign in to comment.