I'm trying to emulate standard DOM onchange event behavior in React. The React onChange event acts like the DOM oninput event, firing every time a key entry is made, rather than when the entry is complete. This makes verifying input difficult unless you use a separate submit button (which I don't). I believe this to be a bug in React.
So far, I've discovered the following techniques come close:
- Emulate submit on loss of focus via an onBlur event handler that submits the value when the focus is lost.
- Emulate submit on hitting the return/enter key via an onKeyUp event handler that submits the entry when evt.key is "Enter" or "Accept".
- For numeric input, emulating submit on increment/decrement (Safari input up/down arrows, up/down keys, up/down scroll wheel) by having the onChange handler detect when the change in value is equal to the step and being careful to compare within a reasonable epsilon for non-integer steps. Number.EPSILON was too small for steps of 0.1, so I had to use something bigger (but still very small). This only approximates the DOM behavior: If a user selects the last digit and provides a digit that changes the value by the step, it will also submit when the digit is entered.
Am I missing any cases? Is there a better technique?