Fix label for number inputs with 0 as value

For an

   <Input type="number" label="label text"/>

the label would overlay the value when it was set to 0 (the integer)
since the checking logic checked for javascript "trueishness".
Now the check is explicit against null, undefined, empty string and NaN.
old
Tobias Bales 2016-03-06 13:56:35 +01:00
parent e2634998af
commit 5029b0d03e
1 changed files with 3 additions and 1 deletions

View File

@ -57,9 +57,11 @@ class Input extends React.Component {
[style.withIcon]: icon
}, this.props.className);
const valuePresent = value !== null && value !== undefined && value !== '' && !Number.isNaN(value);
const InputElement = React.createElement(multiline ? 'textarea' : 'input', {
...others,
className: ClassNames(style.input, {[style.filled]: value}),
className: ClassNames(style.input, {[style.filled]: valuePresent}),
onChange: this.handleChange,
ref: 'input',
role: 'input',