Skip to content
This repository has been archived by the owner on Oct 21, 2020. It is now read-only.

Unclearable NaN value in NumberInput example #17

Open
vasilii-kovalev opened this issue Sep 12, 2020 · 1 comment
Open

Unclearable NaN value in NumberInput example #17

vasilii-kovalev opened this issue Sep 12, 2020 · 1 comment

Comments

@vasilii-kovalev
Copy link

vasilii-kovalev commented Sep 12, 2020

Steps to reproduce:

  1. Go to https://sveltekit.now.sh/#NumberInput
  2. Focus on the input element and clear the value by pressing Backspace button

Actual behavior: NaN value is displayed and can't be cleared/changed even with increase/decrease buttons (arrows).

Expected behavior: value is cleared.

image

@vasilii-kovalev
Copy link
Author

vasilii-kovalev commented Sep 12, 2020

It seems that's because isFinite('') is true:

function isValidValue(value) {
return isFinite(value) || /^-?[0-9.]+$/.test(value);
}

so it is casted to float:

function makeNumber(value) {
return isValidValue(value) ? parseFloat(value) : value;
}

Actually, unit tests could help to catch this issue. I personally know about Svelte Testing Library, maybe there is something else.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant