Skip to content

Support HTML in legend, label and error props, prepare beta release#294

Merged
colinrotherham merged 23 commits intoNHSDigital:mainfrom
Peter-Hudson-G:patch-1
Nov 5, 2025
Merged

Support HTML in legend, label and error props, prepare beta release#294
colinrotherham merged 23 commits intoNHSDigital:mainfrom
Peter-Hudson-G:patch-1

Conversation

@Peter-Hudson-G
Copy link
Contributor

This will hopefully fix that the hint text can be string as well as an element (which is supported).

This will hopefully fix that the hint text can be string as well as an element (which is supported).
@colinrotherham
Copy link
Collaborator

colinrotherham commented Oct 21, 2025

Thanks @Peter-Hudson-G 🙌

Good thinking. Would you mind doing the same for legend please?

To prevent accessibility issues, can you please add some tests (and new storybook examples) using phrasing content only? For example, adding <span class="nhsuk-u-nowrap"> within the hint text inner HTML:

Text only

You would have got these vaccinations at school, from your GP surgery or another healthcare provider

HTML content

This is a 10 digit number (like <span class="nhsuk-u-nowrap">999 123 4567</span>) that you can find on an NHS letter, prescription or in the NHS App

Then we can get this into the next beta release

@colinrotherham
Copy link
Collaborator

Looks like we need it for label, legend and error as well as hint

For consistency with NHS.UK frontend where both text and HTML are supported

@Peter-Hudson-G
Copy link
Contributor Author

It's escalated a little bit from one file. Should hopefully now reflect what I interpenetrated your review meant @colinrotherham .

Co-authored-by: Colin Rotherham <work@colinr.com>
Peter-Hudson-G and others added 2 commits October 21, 2025 15:10
Co-authored-by: Colin Rotherham <work@colinr.com>
@colinrotherham
Copy link
Collaborator

Hi @Peter-Hudson-G

Hope you didn't mind but I've gone ahead and added legend and label support

I've also swapped ReactNode for ReactElement otherwise the following types were allowed:

  | number
  | bigint
  | boolean
  | Iterable<React.ReactNode>
  | React.ReactPortal
  | Promise<AwaitedReactNode>
  | null

I'm very aware that teams might have seen the new storybook examples as ready-to-use in production so I've only included heading caption examples. Full coverage for the other types can be found in tests though

Are you happy with the PR as is it now?

@Peter-Hudson-G
Copy link
Contributor Author

Hi @colinrotherham , Looks good. I guess thinking about it the if(!hint) { return null } only works so far.

@colinrotherham
Copy link
Collaborator

Hi @colinrotherham , Looks good. I guess thinking about it the if(!hint) { return null } only works so far.

Do you have worries about that bit?

Once this PR is merged, error messages will match hint, label and legend behaviour:

if (!children) {
return null;
}

if (!children) {
return null;
}

@Peter-Hudson-G
Copy link
Contributor Author

Peter-Hudson-G commented Nov 4, 2025

Not at all. If you're now fixing it to string or an element a boolean true or number won't sneak past. I came close to using the same thing, but just thought ReactNode covered both nicely.

@colinrotherham colinrotherham changed the title Update FormTypes.ts Support HTML in legend, label and error props Nov 5, 2025
@colinrotherham colinrotherham changed the title Support HTML in legend, label and error props Support HTML in legend, label and error props, prepare beta release Nov 5, 2025
@sonarqubecloud
Copy link

sonarqubecloud bot commented Nov 5, 2025

@colinrotherham colinrotherham added this pull request to the merge queue Nov 5, 2025
Merged via the queue into NHSDigital:main with commit 2da48ca Nov 5, 2025
3 checks passed
@colinrotherham
Copy link
Collaborator

Thanks @Peter-Hudson-G, this is now released in v6.0.0-beta.4

@Peter-Hudson-G
Copy link
Contributor Author

Cheers @colinrotherham . My TypeScript is now happy.

@Peter-Hudson-G Peter-Hudson-G deleted the patch-1 branch November 7, 2025 09:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants