Bug fix: Prevent event propagation on invalid key presses #512
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello! I noticed a behaviour that looks a bit weird to me and led to a bug ticket in Production (here for Qonto employees).
When
@numberOfDecimal
is set to0
(so@value
should always be an integer), following filtering logic is used fore
,,
, and.
key presses:But, since the events are not prevented from bubbling, you can actually type those characters in the input. The value is then converted to an integer on focus out. This leads to some weird states because inputs like
10.5
are actuallyNaN
, while10,5
would be correctly rounded to10
.You can see here how the input behaves before and after preventing events from bubbling.
With propagation:
TestApp.Tests.-.13.July.2023.mp4
Without propagation:
TestApp.Tests.-.13.July.2023.1.mp4
I think preventing the event from propagating would make the component behave in a more rational way: if the input value is an integer, you shouldn't even be allowed to type
e
or a comma in the same way you can't type a letter or any other symbol.Note on testing: I tried modifying the existing tests, but it seems that
typeIn
testing helper doesn't actually work like manually typing, so I don't think there's really a way to test this behaviour. The changes added in the PR don't makee, . and , key should be masked when numberOfDecimal={{0}}
test fail.