Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nuxt UI - UInput Type Number - weird behaviour with decimals #1722

Open
KazTheCreator opened this issue Apr 26, 2024 · 7 comments
Open

Nuxt UI - UInput Type Number - weird behaviour with decimals #1722

KazTheCreator opened this issue Apr 26, 2024 · 7 comments
Labels
bug Something isn't working

Comments

@KazTheCreator
Copy link

KazTheCreator commented Apr 26, 2024

Description

Hey!
Im using an UInput type number and encountered something strange.
It is not possible to write the number "1.04" or "0.06". The culprit seems to be the "0" after the ".".
Further example of working decimal: "1.14", 1.56"
It works fine if you use "," as a comma but my mobile phones number keyboard only provides ".".

The same behvaiour can be tested here:
https://ui.nuxt.com/components/input

Im using Mac and Chrome to test.

Let me know what you think! :)

@KazTheCreator KazTheCreator added the question Further information is requested label Apr 26, 2024
@moshetanzer
Copy link
Collaborator

Hi @KazTheCreator ,

Seems to be working fine on my side. What device are you using?

@vvadymk
Copy link

vvadymk commented Apr 28, 2024

Hi!
I have the same behavior.
When I add decimal with '.' and the first 0 after the '.' the zero is cut of, but as it is described with ',' it works good.

I use Mac and Brave.

@moshetanzer
Copy link
Collaborator

moshetanzer commented Apr 28, 2024

@KazTheCreator @vvadymk Yeah. Got it will try submit a PR to fix. Think it has to do with the 'looseNumber' function. @benjamincanac any input? Should I just add a check to only convert to number if doesn't start with 0? It seems a bit complex unless we remove this?

@moshetanzer moshetanzer added bug Something isn't working and removed question Further information is requested labels Apr 28, 2024
@KazTheCreator
Copy link
Author

Thank you guys! If you need further information from me - tell me! :)

@benjamincanac
Copy link
Member

@romhml Any insight on this?

@KazTheCreator
Copy link
Author

Hey! I dont really know if it helps but anyway.
https://ui.nuxt.com/components/input#type

if you enter 0 then :model-value="0"
as soon you enter the dot (0.) then :model-value=""

"0," is behaving fine.

@romhml
Copy link
Collaborator

romhml commented May 7, 2024

I think I found the culprit:

https://github.com/nuxt/ui/blob/dev/src/runtime/components/forms/Input.vue#L194

The looseToNumber function uses parseFloat which replaces 1.0 or 1,0 to 1. Here's a few tests from the node console:

> parseFloat('1,0')
1
> parseFloat('1.0')
1
> parseFloat('1.01')
1.01

We need to tweak the function to preserve the .0 as the user is typing. Might be related to vuejs/vue#11989 and vuejs/vue#7136 too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants