Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix (a11): add aria-invalid to career form fields #817

Merged
merged 8 commits into from
Sep 22, 2024
Merged
7 changes: 6 additions & 1 deletion src/components/forms/checkbox/checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -66,7 +67,10 @@ const CheckboxLabelTextWrapper = ({ label, required }) => {
};

export const Checkbox = (
props: UseControllerProps<any> & { label: string | JSX.Element },
props: UseControllerProps<any> & {
label: string | JSX.Element;
errors: FormErrors;
},
) => {
const { field, fieldState, formState } = useController(props);
const errorMessage = fieldState?.error?.message;
Expand All @@ -89,6 +93,7 @@ export const Checkbox = (
{...props}
id={props.name}
onChange={handleChange}
aria-invalid={Boolean(props.errors?.[props.name])}
/>
<StyledCheckbox checked={checked} hasError={Boolean(fieldState?.error)}>
<Icon show="checkmark_bold" />
Expand Down
5 changes: 4 additions & 1 deletion src/components/forms/file-dropper/file-dropper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,10 @@ export const FileDropper = ({
$hasErrors={Boolean(errors?.documents)}
>
<StyledLabel>
<input {...getInputProps({ ...register(name) })} />
<input
{...getInputProps({ ...register(name) })}
aria-invalid={Boolean(errors?.documents)}
/>
</StyledLabel>
{!hasFiles && illustration && (
<Illustration show={illustration} size={IllustrationSize.NORMAL} />
Expand Down
8 changes: 7 additions & 1 deletion src/components/forms/text-area/text-area.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -32,6 +36,7 @@ export const TextArea = (
props: UseControllerProps<FormDataProps> & {
label: string;
placeholder?: string;
errors?: FieldErrors;
},
) => {
const { field, fieldState, formState } = useController(props);
Expand All @@ -47,6 +52,7 @@ export const TextArea = (
)}
<StyledTextArea
aria-required={true}
aria-invalid={Boolean(props.errors?.[props.name])}
$hasError={Boolean(errorMessage)}
disabled={formState.isSubmitting}
{...field}
Expand Down
8 changes: 7 additions & 1 deletion src/components/forms/text-input/text-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 { FormDataProps } from '../../pages/career-details/new-career-form/career-form';

const Input = styled.input<{ $hasError?: boolean }>`
Expand Down Expand Up @@ -50,6 +54,7 @@ export const TextInput = (
props: UseControllerProps<FormDataProps> & {
label: string;
placeholder?: string;
errors?: FieldErrors;
},
) => {
const { field, fieldState, formState } = useController(props);
Expand All @@ -66,6 +71,7 @@ export const TextInput = (
<Input
type={'text'}
aria-required={true}
aria-invalid={Boolean(props.errors?.[props.name])}
virus-rpi marked this conversation as resolved.
Show resolved Hide resolved
$hasError={Boolean(errorMessage)}
disabled={formState.isSubmitting}
id={props.name}
virus-rpi marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const CareerDetailsFileText = () => {
);
};

export const CareerDetailsCheckbox = ({ control }) => {
export const CareerDetailsCheckbox = ({ control, errors }) => {
const { t } = useTranslation();

return (
Expand All @@ -70,6 +70,7 @@ export const CareerDetailsCheckbox = ({ control }) => {
}
control={control}
rules={{ required: t('career.error.approval') }}
errors={errors}
/>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
/>
<TextInput
name="last_name"
label={t('career.last-name')}
control={control}
rules={{ required: t('career.error.last-name') }}
errors={errors}
/>

<TextInput
Expand All @@ -139,21 +141,25 @@ export const Form = (props: CareerFormProps) => {
message: t('career.error.email-undefined'),
},
}}
errors={errors}
/>
<TextInput
name="location"
label={t('career.location')}
control={control}
errors={errors}
/>
<TextInput
name="available_from"
label={t('career.available-from')}
control={control}
errors={errors}
/>
<TextInput
name="salary_expectations"
label={t('career.salary-expectations')}
control={control}
errors={errors}
/>
</FormLayout>
<TextArea
Expand All @@ -167,6 +173,7 @@ export const Form = (props: CareerFormProps) => {
message: t('career.error.cover-letter-length'),
},
}}
errors={errors}
/>

<br />
Expand All @@ -179,7 +186,7 @@ export const Form = (props: CareerFormProps) => {
/>
<CareerDetailsFileText />
<br />
<CareerDetailsCheckbox control={control} />
<CareerDetailsCheckbox control={control} errors={errors} />
<br />
<CareerDetailsSubmitButton
errors={errors}
Expand Down