From 67353672c9cc72ad85ee5f12ff80c48a2e6fc8fb Mon Sep 17 00:00:00 2001 From: "noa.santo" Date: Tue, 10 Sep 2024 17:59:35 +0200 Subject: [PATCH 1/6] fix (a11y): add aria-invalid to career form fields --- src/components/forms/checkbox/checkbox.tsx | 7 ++++++- src/components/forms/file-dropper/file-dropper.tsx | 5 ++++- src/components/forms/text-area/text-area.tsx | 8 +++++++- src/components/forms/text-input/text-input.tsx | 8 +++++++- .../new-career-form/career-form-fields.tsx | 3 ++- .../pages/career-details/new-career-form/career-form.tsx | 9 ++++++++- 6 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/components/forms/checkbox/checkbox.tsx b/src/components/forms/checkbox/checkbox.tsx index 0085b7e9a..b2702b39c 100644 --- a/src/components/forms/checkbox/checkbox.tsx +++ b/src/components/forms/checkbox/checkbox.tsx @@ -6,6 +6,7 @@ import { TextStyles } from '../../typography'; import { Icon } from '../../ui/icon/icon'; import { StyledErrorMessage } from '../text-input/text-input'; import { up } from '../../support/breakpoint'; +import { FormErrors } from '../../pages/career-details/new-career-form/career-form'; const CheckboxLabel = styled.label` display: inline-flex; @@ -66,7 +67,10 @@ const CheckboxLabelTextWrapper = ({ label, required }) => { }; export const Checkbox = ( - props: UseControllerProps & { label: string | JSX.Element }, + props: UseControllerProps & { + label: string | JSX.Element; + errors: FormErrors; + }, ) => { const { field, fieldState, formState } = useController(props); const errorMessage = fieldState?.error?.message; @@ -89,6 +93,7 @@ export const Checkbox = ( {...props} id={props.name} onChange={handleChange} + aria-invalid={Boolean(props.errors?.[props.name])} /> diff --git a/src/components/forms/file-dropper/file-dropper.tsx b/src/components/forms/file-dropper/file-dropper.tsx index 9cd66a793..3ff03e118 100644 --- a/src/components/forms/file-dropper/file-dropper.tsx +++ b/src/components/forms/file-dropper/file-dropper.tsx @@ -211,7 +211,10 @@ export const FileDropper = ({ $hasErrors={Boolean(errors?.documents)} > - + {!hasFiles && illustration && ( diff --git a/src/components/forms/text-area/text-area.tsx b/src/components/forms/text-area/text-area.tsx index 181dc5f3a..7b9fecd54 100644 --- a/src/components/forms/text-area/text-area.tsx +++ b/src/components/forms/text-area/text-area.tsx @@ -2,7 +2,11 @@ import React from 'react'; import styled, { css } from 'styled-components'; import { TextStyles } from '../../typography'; import { theme } from '../../layout/theme'; -import { useController, UseControllerProps } from 'react-hook-form'; +import { + FieldErrors, + useController, + UseControllerProps, +} from 'react-hook-form'; import { StyledErrorMessage, Label } from '../text-input/text-input'; import { FormDataProps } from '../../pages/career-details/new-career-form/career-form'; @@ -32,6 +36,7 @@ export const TextArea = ( props: UseControllerProps & { label: string; placeholder?: string; + errors?: FieldErrors; }, ) => { const { field, fieldState, formState } = useController(props); @@ -47,6 +52,7 @@ export const TextArea = ( )} ` @@ -50,6 +54,7 @@ export const TextInput = ( props: UseControllerProps & { label: string; placeholder?: string; + errors?: FieldErrors; }, ) => { const { field, fieldState, formState } = useController(props); @@ -66,6 +71,7 @@ export const TextInput = ( { ); }; -export const CareerDetailsCheckbox = ({ control }) => { +export const CareerDetailsCheckbox = ({ control, errors }) => { const { t } = useTranslation(); return ( @@ -70,6 +70,7 @@ export const CareerDetailsCheckbox = ({ control }) => { } control={control} rules={{ required: t('career.error.approval') }} + errors={errors} /> ); }; diff --git a/src/components/pages/career-details/new-career-form/career-form.tsx b/src/components/pages/career-details/new-career-form/career-form.tsx index 8cc7d9b12..9a41cd7d9 100644 --- a/src/components/pages/career-details/new-career-form/career-form.tsx +++ b/src/components/pages/career-details/new-career-form/career-form.tsx @@ -120,12 +120,14 @@ export const Form = (props: CareerFormProps) => { label={t('career.first-name')} control={control} rules={{ required: t('career.error.first-name') }} + errors={errors} /> { message: t('career.error.email-undefined'), }, }} + errors={errors} />