Skip to content

Commit ed2dba7

Browse files
review update
1 parent e2828fd commit ed2dba7

File tree

10 files changed

+19834
-11483
lines changed

10 files changed

+19834
-11483
lines changed

package-lock.json

Lines changed: 13320 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/form-elements/error-message/ErrorMessage.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import React from 'react';
12
import classNames from 'classnames';
23
import { type ComponentPropsWithoutRef, type FC } from 'react';
34

@@ -11,7 +12,7 @@ export const ErrorMessage: FC<ErrorMessageProps> = ({
1112
children,
1213
...rest
1314
}) => {
14-
if (!children || typeof children !== 'string') {
15+
if (!children || (typeof children !== 'string' && !React.isValidElement(children) && !Array.isArray(children))) {
1516
return null;
1617
}
1718

src/components/form-elements/error-message/__tests__/ErrorMessage.test.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,9 @@ describe('ErrorMessage', () => {
2525

2626
expect(container.querySelector('.nhsuk-u-visually-hidden')).toBeFalsy();
2727
});
28+
29+
it('contains HTML', () => {
30+
const { container } = render(<ErrorMessage>Error<span>this errored</span></ErrorMessage>);
31+
expect(container.innerHTML).toMatch(`Error<span>this errored</span>`);
32+
})
2833
});

src/components/form-elements/error-message/__tests__/__snapshots__/ErrorMessage.test.tsx.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
22

3+
exports[`ErrorMessage contains HTML: ErrorMessage 1`] = `<div />`;
4+
35
exports[`ErrorMessage matches snapshot: ErrorMessage 1`] = `
46
<div>
57
<span

src/components/form-elements/label/__tests__/Label.test.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,11 @@ describe('Label', () => {
5353

5454
expect(container.querySelector('label')).toBeNull();
5555
});
56+
57+
it('renders with HTML', () => {
58+
const { container } = render(<Label>Text<span>and text within HTML</span></Label>);
59+
60+
expect(container.querySelector('label')?.innerHTML).toMatch('Text<span>and text within HTML</span>')
61+
62+
});
5663
});

src/components/form-elements/legend/__tests__/Legend.test.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,11 @@ describe('Legend', () => {
4343

4444
expect(container.querySelector('legend')).toBeNull();
4545
});
46+
47+
it('renders with HTML', () => {
48+
const { container } = render(<Legend>Text<span>and text within HTML</span></Legend>);
49+
50+
expect(container.querySelector('legend')?.innerHTML).toMatch('Text<span>and text within HTML</span>')
51+
52+
});
4653
});

stories/Form Elements/ErrorMessage.stories.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,8 @@ export const EmptyVisuallyHiddenText: Story = {
4545
args: { visuallyHiddenText: '' },
4646
argTypes: { visuallyHiddenText: { control: false } },
4747
};
48+
49+
export const HTML: Story = {
50+
args: { children: <>Enter your full name (or call <span className="nhsuk-u-nowrap">999 123 4567</span>)</>},
51+
argTypes: { visuallyHiddenText: { control: false } },
52+
}

stories/Form Elements/Fieldset.stories.tsx

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export default meta;
3434
type Story = StoryObj<typeof Fieldset>;
3535

3636
export const Standard: Story = {
37-
render: (args) => (
37+
render: () => (
3838
<Fieldset>
3939
<Fieldset.Legend size="l">What is your address?</Fieldset.Legend>
4040
<TextInput
@@ -68,7 +68,7 @@ export const Standard: Story = {
6868
};
6969

7070
export const WithLegendAsAPageHeading: Story = {
71-
render: (args) => (
71+
render: () => (
7272
<Fieldset>
7373
<Fieldset.Legend isPageHeading>What is your address?</Fieldset.Legend>
7474
</Fieldset>
@@ -77,7 +77,7 @@ export const WithLegendAsAPageHeading: Story = {
7777

7878
export const WithCustomLegendSizeS: Story = {
7979
name: 'With Bold Text (S)',
80-
render: (args) => (
80+
render: () => (
8181
<Fieldset>
8282
<Fieldset.Legend size="s">What is your address?</Fieldset.Legend>
8383
</Fieldset>
@@ -86,7 +86,7 @@ export const WithCustomLegendSizeS: Story = {
8686

8787
export const WithCustomLegendSizeM: Story = {
8888
name: 'With Custom Size (M)',
89-
render: (args) => (
89+
render: () => (
9090
<Fieldset>
9191
<Fieldset.Legend size="m">What is your address?</Fieldset.Legend>
9292
</Fieldset>
@@ -95,7 +95,7 @@ export const WithCustomLegendSizeM: Story = {
9595

9696
export const WithCustomLegendSizeL: Story = {
9797
name: 'With Custom Size (L)',
98-
render: (args) => (
98+
render: () => (
9999
<Fieldset>
100100
<Fieldset.Legend size="l">What is your address?</Fieldset.Legend>
101101
</Fieldset>
@@ -104,9 +104,18 @@ export const WithCustomLegendSizeL: Story = {
104104

105105
export const WithCustomLegendSizeXL: Story = {
106106
name: 'With Custom Size (XL)',
107-
render: (args) => (
107+
render: () => (
108108
<Fieldset>
109109
<Fieldset.Legend size="xl">What is your address?</Fieldset.Legend>
110110
</Fieldset>
111111
),
112112
};
113+
114+
export const WithHTML: Story = {
115+
name: 'With HTML',
116+
render: () => (
117+
<Fieldset>
118+
<Fieldset.Legend>What is your address? <strong>small note: this is your home address</strong></Fieldset.Legend>
119+
</Fieldset>
120+
),
121+
};

stories/Form Elements/Label.stories.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,10 @@ export const WithCustomSizeXL: Story = {
5151
size: 'xl',
5252
},
5353
};
54+
55+
export const WithHTML: Story = {
56+
name: 'With HTML',
57+
args: {
58+
children: <>This has <span>a span HTML element</span></>,
59+
},
60+
};

0 commit comments

Comments
 (0)