From 246a6c5572cde13ba7a044a3fb114e2af54b3f95 Mon Sep 17 00:00:00 2001 From: kalasgarov Date: Wed, 20 Nov 2024 11:50:45 -0800 Subject: [PATCH] feat: improve accessibility for single field components tckt-000 --- .../components/DateOfBirth/DateOfBirth.tsx | 41 +++++++++++++------ .../Form/components/EmailInput/EmailInput.tsx | 17 +++++--- .../components/PhoneNumber/PhoneNumber.tsx | 11 ++--- .../SelectDropdown/SelectDropdown.tsx | 23 +++++++---- 4 files changed, 60 insertions(+), 32 deletions(-) diff --git a/packages/design/src/Form/components/DateOfBirth/DateOfBirth.tsx b/packages/design/src/Form/components/DateOfBirth/DateOfBirth.tsx index 79f4432b..6e43a5cb 100644 --- a/packages/design/src/Form/components/DateOfBirth/DateOfBirth.tsx +++ b/packages/design/src/Form/components/DateOfBirth/DateOfBirth.tsx @@ -1,4 +1,5 @@ import React from 'react'; +import classNames from 'classnames'; import { useFormContext } from 'react-hook-form'; import { type DateOfBirthProps } from '@atj/forms'; import { type PatternComponent } from '../../index.js'; @@ -36,20 +37,33 @@ export const DateOfBirthPattern: PatternComponent = ({ {required && *} {hint && ( - + {hint} )} + {error && ( + + )}
@@ -81,22 +99,21 @@ export const DateOfBirthPattern: PatternComponent = ({ Year
- {error && ( - - {error.message} - - )} ); }; diff --git a/packages/design/src/Form/components/EmailInput/EmailInput.tsx b/packages/design/src/Form/components/EmailInput/EmailInput.tsx index 31588db4..b49e14f9 100644 --- a/packages/design/src/Form/components/EmailInput/EmailInput.tsx +++ b/packages/design/src/Form/components/EmailInput/EmailInput.tsx @@ -1,4 +1,5 @@ import React from 'react'; +import classNames from 'classnames'; import { useFormContext } from 'react-hook-form'; import { type EmailInputProps } from '@atj/forms'; import { type PatternComponent } from '../../index.js'; @@ -10,6 +11,7 @@ export const EmailInputPattern: PatternComponent = ({ error, }) => { const { register } = useFormContext(); + const errorId = `input-error-message-${emailId}`; return (
@@ -18,20 +20,23 @@ export const EmailInputPattern: PatternComponent = ({ {label} {required && *} + {error && ( + + )} - {error && ( - - {error.message} - - )}
); }; diff --git a/packages/design/src/Form/components/PhoneNumber/PhoneNumber.tsx b/packages/design/src/Form/components/PhoneNumber/PhoneNumber.tsx index ee4adc1d..ab4c471f 100644 --- a/packages/design/src/Form/components/PhoneNumber/PhoneNumber.tsx +++ b/packages/design/src/Form/components/PhoneNumber/PhoneNumber.tsx @@ -13,6 +13,7 @@ export const PhoneNumberPattern: PatternComponent = ({ value, }) => { const { register } = useFormContext(); + const errorId = `input-error-message-${phoneId}`; return (
@@ -28,16 +29,12 @@ export const PhoneNumberPattern: PatternComponent = ({ {required && *} {hint && ( -
+
{hint}
)} {error && ( -
diff --git a/packages/design/src/Form/components/SelectDropdown/SelectDropdown.tsx b/packages/design/src/Form/components/SelectDropdown/SelectDropdown.tsx index ab9c3485..49cd0a6f 100644 --- a/packages/design/src/Form/components/SelectDropdown/SelectDropdown.tsx +++ b/packages/design/src/Form/components/SelectDropdown/SelectDropdown.tsx @@ -1,6 +1,6 @@ import React from 'react'; +import classNames from 'classnames'; import { useFormContext } from 'react-hook-form'; - import { type SelectDropdownProps } from '@atj/forms'; import { type PatternComponent } from '../../index.js'; @@ -12,13 +12,27 @@ export const SelectDropdownPattern: PatternComponent = ({ error, }) => { const { register } = useFormContext(); + const errorId = `input-error-message-${selectId}`; + return (
- @@ -28,11 +42,6 @@ export const SelectDropdownPattern: PatternComponent = ({ ))} - {error && ( - - {error.message} - - )}
); };