Skip to content

Commit

Permalink
Fix raw html in the research form checkbox label
Browse files Browse the repository at this point in the history
  • Loading branch information
nygrenh committed Mar 19, 2024
1 parent 9b27c0b commit f5534e0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const ResearchFormCheckBoxBlock: React.FC<
<>
<CheckBox
label={parseText(props.data.attributes.content, terms).parsedText}
labelIsRawHtml
checked={questionIdsAndAnswers[props.data.clientId]}
onChange={() => handleChange(!questionIdsAndAnswers[props.data.clientId])}
/>
Expand Down
16 changes: 14 additions & 2 deletions shared-module/src/components/InputFields/CheckBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,21 @@ export interface CheckboxProps extends InputHTMLAttributes<HTMLInputElement> {
error?: boolean
checked?: boolean
onChangeByValue?: (checked: boolean, name?: string) => void
labelIsRawHtml?: boolean
}

const CheckBox = forwardRef<HTMLInputElement, CheckboxProps>(
({ onChangeByValue, onChange, className, checked, ...rest }: CheckboxProps, ref) => {
(
{
onChangeByValue,
onChange,
className,
checked,
labelIsRawHtml = false,
...rest
}: CheckboxProps,
ref,
) => {
const handleOnChange = (event: React.ChangeEvent<HTMLInputElement>) => {
if (onChangeByValue) {
const {
Expand Down Expand Up @@ -110,9 +121,10 @@ const CheckBox = forwardRef<HTMLInputElement, CheckboxProps>(
aria-invalid={rest.error !== undefined}
onChange={handleOnChange}
ref={ref}
dangerouslySetInnerHTML={labelIsRawHtml ? { __html: rest.label } : undefined}
{...rest}
/>
<span>{rest.label}</span>
{!labelIsRawHtml && <span>{rest.label}</span>}
</Label>
{rest.error && (
<span
Expand Down

0 comments on commit f5534e0

Please sign in to comment.