Skip to content
This repository was archived by the owner on Aug 13, 2021. It is now read-only.

Commit 27cea06

Browse files
authored
Don't try to format an undefined value in NumericInput (#63)
1 parent cf2f609 commit 27cea06

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "uiuiui",
3-
"version": "0.5.17",
3+
"version": "0.5.18",
44
"main": "dist/uiuiui.cjs.js",
55
"module": "dist/uiuiui.js",
66
"source": "src/index.js",

src/Input/NumericInput.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ class NumericInput extends React.PureComponent {
3838
}
3939
}
4040

41+
// Don't format user input if it's not defined (so we don't end up with NaN)
4142
format_user_input(value) {
42-
return this.format_value(parseFloat(value));
43+
return value ? this.format_value(parseFloat(value)) : value;
4344
}
4445

4546
format_value(value, method = clamp) {

src/Input/stories/index.stories.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,25 @@ storiesOf('Input', module)
5252
</Husk>
5353
);
5454
})
55+
.add('NumericInput, Controller, Set to undefined', () => {
56+
return (
57+
<Husk useState={{ value: 50 }}>
58+
{(state, setState) => (
59+
<React.Fragment>
60+
<NumericInput value={state.value} onChange={value => setState({ value })} />
61+
62+
<button
63+
onClick={() => {
64+
setState({ value: undefined });
65+
}}
66+
>
67+
set to undefined
68+
</button>
69+
</React.Fragment>
70+
)}
71+
</Husk>
72+
);
73+
})
5574
.add('ColorInput', () => {
5675
return (
5776
<ColorInput value="tomato" current={value => <Swatch color={value} />}>

0 commit comments

Comments
 (0)