diff --git a/dotcom-rendering/src/web/components/Callout/CheckboxSelect.tsx b/dotcom-rendering/src/web/components/Callout/CheckboxSelect.tsx index 7fdc4539ced..09e533c6f7b 100644 --- a/dotcom-rendering/src/web/components/Callout/CheckboxSelect.tsx +++ b/dotcom-rendering/src/web/components/Callout/CheckboxSelect.tsx @@ -1,17 +1,27 @@ import { Checkbox, CheckboxGroup } from '@guardian/source-react-components'; -import { CampaignFieldCheckbox } from '../../../types/content'; -import { FieldLabel } from './FieldLabel'; +import type { CampaignFieldCheckbox } from 'src/types/content'; type Props = { formField: CampaignFieldCheckbox; formData: { [key in string]: string[] }; setFormData: React.Dispatch>; + validationErrors?: { [key in string]: string }; }; -export const CheckboxSelect = ({ formField, formData, setFormData }: Props) => ( +export const CheckboxSelect = ({ + formField, + formData, + setFormData, + validationErrors, +}: Props) => ( <> - - + {formField.options.map((option, index) => { // data related to this field is mapped to `formData` using `formField.id` // We cannot assume that the data exists, so we need to check if `formField.id` key exists in `formData` @@ -39,6 +49,7 @@ export const CheckboxSelect = ({ formField, formData, setFormData }: Props) => ( label={option.label} value={option.value} checked={isCheckboxChecked} + error={validationErrors?.[formField.id] ? true : false} onChange={() => { setFormData({ ...formData, diff --git a/dotcom-rendering/src/web/components/Callout/FieldLabel.tsx b/dotcom-rendering/src/web/components/Callout/FieldLabel.tsx index eddf4ae99ba..c0c9de074d1 100644 --- a/dotcom-rendering/src/web/components/Callout/FieldLabel.tsx +++ b/dotcom-rendering/src/web/components/Callout/FieldLabel.tsx @@ -1,6 +1,10 @@ import { css } from '@emotion/react'; -import { neutral, textSans } from '@guardian/source-foundations'; -import { CampaignFieldType } from '../../../types/content'; +import { + neutral, + textSans, + visuallyHidden, +} from '@guardian/source-foundations'; +import type { CampaignFieldType } from 'src/types/content'; const fieldLabelStyles = css` ${textSans.medium({ fontWeight: 'bold' })} @@ -16,15 +20,22 @@ const optionalTextStyles = css` padding-left: 5px; `; -export const FieldLabel = ({ formField }: { formField: CampaignFieldType }) => ( -