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

[Bug]: allowEmpty behaviour in NumberInput is not able to distinguish empty string with characters other than numbers #13624

Closed
2 tasks done
nikhil-isaac opened this issue Apr 18, 2023 · 8 comments

Comments

@nikhil-isaac
Copy link

Package

carbon-components-react

Browser

Chrome, Safari, Firefox

Package version

v7.59.6

React version

v17.0.2

Description

When I set allowEmpty to true for NumberInput, then whenever I type any characters other than numbers(like a, b, c, etc), I get only empty string("") in onChange prop. I would like to distinguish between typing an actual empty string(valid value for our usecase) and typing any characters other than numbers(invalid value for our usecase).

Reproduction/example

https://codesandbox.io/s/carbon-number-input-allow-empty-invalid-issue-97mho?file=/src/index.js

Steps to reproduce

  1. Type empty string, the component allows.
  2. Type any characters other than numbers(like a, b, c, etc) the component allows them too.
  3. Expectation: To allow empty string(""), but not allow characters other than numbers and empty string(like a, b, c, etc).

Suggested Severity

Severity 2 = User cannot complete task, and/or no workaround within the user experience of a given component.

Application/PAL

Cloud & Cognitive Software

Code of Conduct

@francinelucca
Copy link
Collaborator

@nikhil-issac would you be able to insert a screen recording reproducing the issue? I can't seem to do it from the reproduction steps.
TIA!

@francinelucca francinelucca added the status: needs reproduction Issues lacking a code reproduction label Apr 18, 2023
@sstrubberg sstrubberg moved this to 🕵️‍♀️ Triage in Design System May 1, 2023
@tay1orjones tay1orjones closed this as not planned Won't fix, can't repro, duplicate, stale May 15, 2023
@github-project-automation github-project-automation bot moved this from 🕵️‍♀️ Triage to ✅ Done in Design System May 15, 2023
@nikhil-isaac
Copy link
Author

nikhil-isaac commented Jul 3, 2023

@francinelucca Sorry for the late response!!!
number-input-allow-empty
The empty string is being generated even when we type non-integer characters like 'a' or 'aa' or '$', which makes it impossible to do number validation when we set allowEmpty to true..

@francinelucca
Copy link
Collaborator

thanks! @nikhil-isaac, I see the issue now. Could you drop that code you're using in the screenrecord into a sandbox? 🙏🏻, looks different than the one in the reproduction steps

@nikhil-isaac
Copy link
Author

@francinelucca
Copy link
Collaborator

Was able to reproduce in firefox, reopening

@shankar343
Copy link

Hi Team, any solutions we got for this issue?

@tay1orjones
Copy link
Member

tay1orjones commented Aug 28, 2023

@shankar343 @nikhil-isaac

The empty string is being generated even when we type non-integer characters like 'a' or 'aa' or '$', which makes it impossible to do number validation when we set allowEmpty to true..

Browsers disagree on how to handle non-numeric input, see this bugzilla thread for more info.

Additionally, NumberInput does not modify the event passed when onChange is called. It's coming straight from the browser.

if (onChange) {
onChange(event, state);
}

This is why onKeyUp was added, so you can work around this and identify the individual keystrokes and implement your own additional validation. There should be nothing preventing this working with allowEmpty.

I hope this helps, and sorry for the lack of information earlier. I'm going to close this as a duplicate but happy to continue the conversation or pursue other options if you have ideas for a different fix or solution to the problem.

@tay1orjones
Copy link
Member

Duplicate of #7039

@tay1orjones tay1orjones marked this as a duplicate of #7039 Aug 28, 2023
@tay1orjones tay1orjones closed this as not planned Won't fix, can't repro, duplicate, stale Aug 28, 2023
@github-project-automation github-project-automation bot moved this from ⏱ Backlog to ✅ Done in Design System Aug 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

No branches or pull requests

4 participants