From 45fcde471b8150ae22b48d3a803342c6aa4f0108 Mon Sep 17 00:00:00 2001
From: Delba de Oliveira <32464864+delbaoliveira@users.noreply.github.com>
Date: Thu, 16 Nov 2023 14:27:20 +0000
Subject: [PATCH] Improve Form Error Accessibility (#450)
---
.../app/ui/invoices/create-form.tsx | 61 ++++++++-----------
.../app/ui/invoices/edit-form.tsx | 61 ++++++++-----------
dashboard/final-example/app/ui/login-form.tsx | 10 +--
3 files changed, 58 insertions(+), 74 deletions(-)
diff --git a/dashboard/final-example/app/ui/invoices/create-form.tsx b/dashboard/final-example/app/ui/invoices/create-form.tsx
index 715ff71..cdbc406 100644
--- a/dashboard/final-example/app/ui/invoices/create-form.tsx
+++ b/dashboard/final-example/app/ui/invoices/create-form.tsx
@@ -44,17 +44,14 @@ export default function Form({ customers }: { customers: CustomerField[] }) {
- {state.errors?.customerId ? (
-
- {state.errors.customerId.map((error: string) => (
-
{error}
+
+ {state.errors?.customerId &&
+ state.errors.customerId.map((error: string) => (
+
+ {error}
+
))}
-
- ) : null}
+
{/* Invoice Amount */}
@@ -77,17 +74,14 @@ export default function Form({ customers }: { customers: CustomerField[] }) {
- {state.errors?.amount ? (
-
- {state.errors.amount.map((error: string) => (
-
{error}
+
+ {state.errors?.amount &&
+ state.errors.amount.map((error: string) => (
+
+ {error}
+
))}
-
- ) : null}
+
{/* Invoice Status */}
@@ -129,24 +123,21 @@ export default function Form({ customers }: { customers: CustomerField[] }) {
- {state.errors?.status ? (
-
- {state.errors.status.map((error: string) => (
-
{error}
+
+ {state.errors?.status &&
+ state.errors.status.map((error: string) => (
+
+ {error}
+
))}
-
- ) : null}
+
- {state.message ? (
-
- ) : null}
+
+ {state.message ? (
+
{state.message}
+ ) : null}
+
- {state.errors?.customerId ? (
-
- {state.errors.customerId.map((error: string) => (
-
{error}
+
+ {state.errors?.customerId &&
+ state.errors.customerId.map((error: string) => (
+
+ {error}
+
))}
-
- ) : null}
+
{/* Invoice Amount */}
@@ -84,17 +81,14 @@ export default function EditInvoiceForm({
- {state.errors?.amount ? (
-
- {state.errors.amount.map((error: string) => (
-
{error}
+
+ {state.errors?.amount &&
+ state.errors.amount.map((error: string) => (
+
+ {error}
+
))}
-
- ) : null}
+
{/* Invoice Status */}
@@ -138,24 +132,21 @@ export default function EditInvoiceForm({
- {state.errors?.status ? (
-
- {state.errors.status.map((error: string) => (
-
{error}
+
+ {state.errors?.status &&
+ state.errors.status.map((error: string) => (
+
+ {error}
+
))}
-
- ) : null}
+
- {state.message ? (
-
- ) : null}
+
+ {state.message ? (
+
{state.message}
+ ) : null}
+
-
+
{state === 'CredentialsSignin' && (
<>
-
- Invalid credentials
-
+
Invalid credentials
>
)}