InputNumber onChange callback should expose the change reason as a second callback parameter
See original GitHub issue- I have searched the issues of this repository and believe that this is not a duplicate.
What problem does this feature solve?
Right now InputNumber’s onChange can be cause by 4 sources: 1) user typing/paste, 2) click up button, 3) click down button, 4) onBlur When making a HOC on top of it, I find it’s impossible to add custom behavior because it’s very hard to figure out why the change happens
What I want to do:
- a. InputNumber only commit value when user press enter, not during typing
- b. press esc will revert to previous value
- c. show a red border when value is not valid number, and not send the value
problems:
- a. and b. pretty tricky to implement, because I need to add keyboard and click listener to guess what caused the change, there are some edge case, like
right click -> paste
I can’t guess correctly - c. when onBlur happens, the value is converted with parseFloat, which is not desired behavior, since things like
1a
would be parsed to 1 and there is no way to know if it’s from onBlur, since custom onBlur handler happens after onChange
I’ve created 2 other tickets related to this. https://github.com/ant-design/ant-design/issues/14685 https://github.com/ant-design/ant-design/issues/14753 both rejected, which I totally understand, because it’s bad practice.
however, in order to implement it in the right way, I really need something to tell me what caused the change
What does the proposed API look like?
onChange : function(value: number | string, source: 'input' | 'up' | 'down' | 'blur')
🖐️ I can contribute to the rc-input-number project myself if you think this change is OK.
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (5 by maintainers)
same requirement
👌Let’s close this first. Will reopen when get the same requirement.