Skip to content

Commit

Permalink
fix(NumberInput): handle case when input is invalid, resolves carbon-…
Browse files Browse the repository at this point in the history
…design-system#436 (carbon-design-system#836)

* fix(NumberInput): handle case when input is invalid, resolves carbon-design-system#436

* fix(NumberInput): handle case when input is invalid, resolves carbon-design-system#436
  • Loading branch information
rezak-otmani authored and marijohannessen committed May 4, 2018
1 parent a15e5b8 commit b00d244
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/components/NumberInput/NumberInput-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@ describe('NumberInput', () => {
let numberInput = wrapper.find('input');
expect(numberInput.prop('value')).toEqual(5);
});

it('should set invalidText when value is empty string', () => {
wrapper.setProps({ value: '' });
const invalidText = wrapper.find('.bx--form-requirement');
expect(invalidText.length).toEqual(1);
expect(invalidText.text()).toEqual('invalid text');
});
});
});

Expand Down
2 changes: 1 addition & 1 deletion src/components/NumberInput/NumberInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export default class NumberInput extends Component {

const inputWrapperProps = {};
let error = null;
if (invalid) {
if (invalid || this.state.value === '') {
inputWrapperProps['data-invalid'] = true;
error = <div className="bx--form-requirement">{invalidText}</div>;
}
Expand Down

0 comments on commit b00d244

Please sign in to comment.