Expose changeObject for all event handlers
Summary
It would be great if all fields' (CardNumberElement, CardExpiryElement, CardCVCElement) event handlers (especially onBlur) had access to the full changeObject.
<CardExpiryElement onBlur={(change) => console.log(change)}/>
// on the actual blur it should log out
{
complete: false,
elementType: "cardExpiry",
empty: false,
error: undefined,
value: '',
...
}
Motivation
Many teams tend to implement error handling on blur rather than on change and without it we have to write way too much code than we should.
Hi @criography: thanks for filing this request!
I definitely understand that the current API shape is not ideal for that use-case. But there are some tricky challenges that make this hard to do. For example: do we emit changes on both events? If people listen to both, do they expect to get only the changes since the last event of any type or all the changes since the last event of the same type? What do we emit if the customer focuses and blurs, but no changes have actually been made?
So while your request makes sense and we will think about it, I wouldn't expect that we will be implementing it shortly.
Hi @asolove-stripe,
thank you for your response :)
These are all interesting questions and I definitely understand your concerns, especialy for such sensitive set of components.
That said, if I may suggest, the closer you stick to the native, browser implementation, the better, as this is what most developers work with on a daily basis. Any deviation from it feels rather unexpected and confusing.
While onChange indeed exposes changed values, the purpose of onBlur or onFocus is not to necessarily communicate changes but expose a state of the field at given user interactions.
So my reccomendation would be to expose your changeObject consistently. Perhaps the name is misleading here, so instead of changeObject call it something like fieldState in your documentation.
Yes, there may be some duplication of exposed data, but it's exactly what any browser does too. Having it allows for much more flexibility and a much better DX – I have looked and worked with a whole lot of 3rd party components or component libraries, and have not seen such strategy, so perhaps a point of reference for a future consideration? :)
Other than that, good job on the library! 🤓
Closing this as this project has migrated to React Stripe.js as of early 2020, which also has a different API. If you believe this is still important, please re-open it there.