mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 10:21:05 +00:00
fix(number-input): empty input should not be coerced to 0 (#1032)
Fixes #1031
This commit is contained in:
parent
4d51250173
commit
222d5a90e4
1 changed files with 6 additions and 1 deletions
|
@ -131,10 +131,15 @@
|
||||||
|
|
||||||
let inputValue = value;
|
let inputValue = value;
|
||||||
|
|
||||||
|
const normalizeValue = (_value) => {
|
||||||
|
if (_value === undefined || _value === "") return _value;
|
||||||
|
return Number(_value);
|
||||||
|
};
|
||||||
|
|
||||||
$: dispatch("change", value);
|
$: dispatch("change", value);
|
||||||
$: incrementLabel = translateWithId("increment");
|
$: incrementLabel = translateWithId("increment");
|
||||||
$: decrementLabel = translateWithId("decrement");
|
$: decrementLabel = translateWithId("decrement");
|
||||||
$: value = Number(inputValue);
|
$: value = normalizeValue(inputValue);
|
||||||
$: error =
|
$: error =
|
||||||
invalid || (!allowEmpty && value === "") || value > max || value < min;
|
invalid || (!allowEmpty && value === "") || value > max || value < min;
|
||||||
$: errorId = `error-${id}`;
|
$: errorId = `error-${id}`;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue