question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NumberInput arrow buttons with decimal step value do not function correctly

See original GitHub issue

What package(s) are you using?

  • carbon-components
  • carbon-components-react

Detailed description

Describe in detail the issue you’re having.

Trying to use NumberInput to set a value that can be fractional, eg. 0.5. Want to use a step value of 0.1 and noticing that the up/down arrows from the React component behave incorrectly and will sometimes be off by some small number, see attached screenshot or codesandbox.

Appears to be a floating point number issue with the react component’s up/down buttons because using the arrow keys in the NumberInput component, or the vanilla html number <input> does not cause this issue.

Is this issue related to a specific component?

<NumberInput>

What did you expect to happen? What happened instead? What would you like to see changed?

arrow step buttons updated to handle decimal numbers

What browser are you working in?

Chrome

What version of the Carbon Design System are you using?

10.9.3

What offering/product do you work on? Any pressing ship or release dates we should be aware of?

Streams on CPD, end of February

Steps to reproduce the issue

  1. use something <NumberInput step={0.1}>

Please create a reduced test case in CodeSandbox

https://codesandbox.io/s/jolly-mahavira-n4u4w

Additional information

image

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
piers-walter-ibmcommented, Feb 27, 2020

I also encountered this issue, and implemented a workaround: here.

Could something like this be added as a prop to NumberInput perhaps

fixFloating={true}

I realise you may not want to interfere with the way javascript handles numbers and leave it as an exercise to the programmer, depending on their use case

0reactions
tay1orjonescommented, Oct 19, 2020

Will monitor how common the use case is

We’ve had this reported in our addons repo https://github.com/carbon-design-system/carbon-addons-iot-react/issues/1693

floating point math is fun

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why the number input is the worst input - Stack Overflow Blog
When the number input contains an invalid value and you retrieve the value, you get a blank string. Valid numbers include more than...
Read more >
How to handle floats and decimal separators with html5 input ...
Here's a fiddle demonstrating that the adding of the step attribute makes it work, and also testing whether the current value is valid:....
Read more >
Numeric Inputs - A Comparison of Browser Defaults | CSS-Tricks
The “pattern” argument not always works. One time I was developing a number field where the user have to enter a decimal number....
Read more >
How To Hide Arrows From Number Input - W3Schools
Try to hover over both number inputs to see the difference: Hidden arrows: Default: Notes on functionality: It is still possible to increment...
Read more >
The HTML5 input types - Learn web development | MDN
It is a helpful aid to guide users to fill out a form accurately, and it can save time: it is useful to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found