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

[NumberField] Bug with increment/decrement buttons for percent unit #1675

Closed
KasiaSmolarska opened this issue Apr 6, 2025 · 4 comments · Fixed by #1676
Closed

[NumberField] Bug with increment/decrement buttons for percent unit #1675

KasiaSmolarska opened this issue Apr 6, 2025 · 4 comments · Fixed by #1676
Labels
bug 🐛 Something doesn't work component: number field This is the name of the generic UI component, not the React module!

Comments

@KasiaSmolarska
Copy link

Description: I am using NumberField from version 1.0.0-alpha.7 and encountered an issue with the increment/decrement buttons and input value behavior when the format is set to { style: "percent" } or { style: "unit", unit: "percent" }.

Current Behavior:

When I set format={{ style: "percent" }}, the increment and decrement buttons work correctly if I set step={0.01}. However, when typing a value directly into the input field, it is automatically multiplied by 100. For example, typing 50 results in 5000%, but I expect it to be 50% without multiplication.

When I set format={{ style: "unit", unit: "percent" }}, the input field works fine (typing 50 results in 50% as expected). However, the increment and decrement buttons do not work properly. They do not respond as expected when trying to increment or decrement the value by 1.

For other unit types like format={{ style: "unit", unit: "liter" }}, both the buttons and the input field behave as expected. The increment/decrement buttons work correctly, and typing values works without any unwanted multiplication.

Expected Behavior:

When style: "unit", unit: "percent" is used, the increment and decrement buttons should work correctly, allowing changes by increments of 1.

Steps to Reproduce:

Set the NumberField component with format={{ style: "percent" }}.

Try using the increment/decrement buttons (they work correctly).

Manually type a value like 50 into the input field and observe that it gets multiplied by 100, resulting in 5000%.

Set the NumberField component with format={{ style: "unit", unit: "percent" }}.

Observe that the input works correctly (typing 50 results in 50%), but the increment and decrement buttons do not work as expected.

Set the NumberField component with other unit types, like format={{ style: "unit", unit: "liter" }}, and observe that everything works as expected.

Link to Sandbox Example: Example on CodeSandbox

Browser Information:

Browser: Chrome

Operating System:

OS: Windows

Please let me know if you need any further details!

@KasiaSmolarska KasiaSmolarska added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Apr 6, 2025
@atomiks atomiks added component: number field This is the name of the generic UI component, not the React module! and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Apr 7, 2025
@atomiks
Copy link
Contributor

atomiks commented Apr 7, 2025

The percentage works with values from 0 to 1, so 0.1 = 10%, 0.5 = 50%, etc.

To solve this, we should probably do this:

  1. If {style: "percent"}, then typing 40 should map to 0.4 instead of 40x100%; they'd still be required to set step={0.01}
  2. If {style: "unit", unit: "percent"}, the step behavior should just work as expected

@KasiaSmolarska
Copy link
Author

Thanks for your response.

However, I want to highlight again the main issue I reported:
When using format={{ style: "unit", unit: "percent" }}, the increment and decrement buttons do not work at all.

This is actually the main reason I opened the issue — the input value itself works fine in this mode (typing 50 results in 50%, as expected), but the step buttons don’t respond.

Just to clarify:

  • style: "percent" → input multiplies by 100 (currently undesirable, but buttons work if step={0.01})
    - style: "unit", unit: "percent" → input works great, but increment/decrement buttons are broken
  • style: "unit", unit: "liter" (and others) → both input and buttons work correctly

Let me know if I can help reproduce this in more detail — I also included a CodeSandbox in the original report.

@atomiks
Copy link
Contributor

atomiks commented Apr 7, 2025

#1676 fixes both configs

@KasiaSmolarska
Copy link
Author

Thanks a lot!

@mj12albert mj12albert changed the title Bug with increment/decrement buttons for percent unit in NumberField [NumberField] Bug with increment/decrement buttons for percent unit Apr 9, 2025
@mj12albert mj12albert added the bug 🐛 Something doesn't work label Apr 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: number field This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants