From 2d2f8d23e1cf7493c62b4b5003d0b448066dcb71 Mon Sep 17 00:00:00 2001 From: Sebastian Sangervasi Date: Wed, 25 Jan 2023 17:18:32 -0800 Subject: [PATCH 1/2] pc/modals: Use chakra isRequired instead of string asterisk --- .../consent-request-modal/ConsentRequestForm.tsx | 10 ++++------ .../privacy-request-modal/PrivacyRequestForm.tsx | 15 ++++++--------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/clients/privacy-center/components/modals/consent-request-modal/ConsentRequestForm.tsx b/clients/privacy-center/components/modals/consent-request-modal/ConsentRequestForm.tsx index 67a109c24f..33f001b127 100644 --- a/clients/privacy-center/components/modals/consent-request-modal/ConsentRequestForm.tsx +++ b/clients/privacy-center/components/modals/consent-request-modal/ConsentRequestForm.tsx @@ -179,10 +179,9 @@ const ConsentRequestForm: React.FC = ({ - - {identityInputs.email === "required" ? "Email*" : "Email"} - + Email = ({ - - {identityInputs.phone === "required" ? "Phone*" : "Phone"} - + Phone = ({ - - {identityInputs.name === "required" ? "Name*" : "Name"} - + Name = ({ - - {identityInputs.email === "required" ? "Email*" : "Email"} - + Email = ({ - - {identityInputs.phone === "required" ? "Phone*" : "Phone"} - + Phone Date: Wed, 25 Jan 2023 18:09:47 -0800 Subject: [PATCH 2/2] pc/modals: FormErrorMessage that always takes up space --- .../components/FormErrorMessage.tsx | 25 +++++++++++++++++++ .../components/modals/VerificationForm.tsx | 4 +-- .../ConsentRequestForm.tsx | 4 +-- .../PrivacyRequestForm.tsx | 4 +-- 4 files changed, 31 insertions(+), 6 deletions(-) create mode 100644 clients/privacy-center/components/FormErrorMessage.tsx diff --git a/clients/privacy-center/components/FormErrorMessage.tsx b/clients/privacy-center/components/FormErrorMessage.tsx new file mode 100644 index 0000000000..8dc8cc9b70 --- /dev/null +++ b/clients/privacy-center/components/FormErrorMessage.tsx @@ -0,0 +1,25 @@ +import { + Box, + FormErrorMessage as ChakraFormErrorMessage, + forwardRef, + useFormControlContext, +} from "@fidesui/react"; + +/** + * This is a thin wrapper around Chakra's FormErrorMessage that leaves room for the error message + * even when the field is valid. This prevents the form from changing height when validation runs, + * which can be annoying on blur. + * + * Chakra Source: + * https://github.com/chakra-ui/chakra-ui/blob/%40chakra-ui/react%401.8.8/packages/form-control/src/form-error.tsx + */ +export const FormErrorMessage: typeof ChakraFormErrorMessage = forwardRef( + (props, ref) => { + const field = useFormControlContext(); + if (!field?.isInvalid) { + return ; + } + + return ; + } +); diff --git a/clients/privacy-center/components/modals/VerificationForm.tsx b/clients/privacy-center/components/modals/VerificationForm.tsx index ee40c70786..bde38566ff 100644 --- a/clients/privacy-center/components/modals/VerificationForm.tsx +++ b/clients/privacy-center/components/modals/VerificationForm.tsx @@ -3,7 +3,6 @@ import { Button, chakra, FormControl, - FormErrorMessage, HStack, Input, ModalBody, @@ -21,6 +20,7 @@ import { ErrorToastOptions } from "~/common/toast-options"; import { Headers } from "headers-polyfill"; import { addCommonHeaders } from "~/common/CommonHeaders"; import { useLocalStorage } from "~/common/hooks"; +import { FormErrorMessage } from "~/components/FormErrorMessage"; import { hostUrl } from "~/constants"; import { ModalViews, VerificationType } from "./types"; @@ -178,7 +178,7 @@ const VerificationForm: React.FC = ({ A verification code has been sent. Return to this window and enter the code below. - + = ({ We will send you a verification code. ) : null} - + {identityInputs.email ? ( = ({ {action.description} - + {identityInputs.name ? (