From fffd3e9db3be6b0bc140dacbb7d5a4768d1dfe8b Mon Sep 17 00:00:00 2001 From: Les Orchard Date: Mon, 26 Aug 2019 19:02:39 -0400 Subject: [PATCH] fix(payments): better validation for Stripe elements - add onBlur handling to trigger validation - support for custom onValidate prop for Stripe fields fixes #2262 --- .../src/components/fields.test.tsx | 70 +++++++++++++++++-- .../src/components/fields.tsx | 53 ++++++++++---- 2 files changed, 104 insertions(+), 19 deletions(-) diff --git a/packages/fxa-payments-server/src/components/fields.test.tsx b/packages/fxa-payments-server/src/components/fields.test.tsx index 521067034ad..2c6c91c642b 100644 --- a/packages/fxa-payments-server/src/components/fields.test.tsx +++ b/packages/fxa-payments-server/src/components/fields.test.tsx @@ -1,7 +1,6 @@ import React, { useState, useCallback, useContext, useRef } from 'react'; -import { render, cleanup, fireEvent, prettyDOM } from '@testing-library/react'; +import { render, cleanup, fireEvent } from '@testing-library/react'; import '@testing-library/jest-dom/extend-expect'; -import { ReactStripeElements } from 'react-stripe-elements'; import { FieldGroup, Form, @@ -288,12 +287,23 @@ describe('StripeElement', () => { constructor(props: MockStripeElementProps) { super(props); } - handleClick = (ev: React.MouseEvent) => { + handleClick = (ev: React.MouseEvent) => { ev.preventDefault(); this.props.onChange(value); }; + handleBlur = (ev: React.FocusEvent) => { + ev.preventDefault(); + this.props.onBlur(); + }; render() { - return