Skip to content

Commit 12ec82f

Browse files
Remove support for error lines without error messages
1 parent 4539418 commit 12ec82f

File tree

18 files changed

+331
-282
lines changed

18 files changed

+331
-282
lines changed

docs/upgrade-to-6.0.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,21 @@ You must make the following changes to `<Fieldset.Legend>` components:
5454
</Fieldset>
5555
```
5656

57+
### Make sure error message text is added
58+
59+
For accessibility reasons and to align with NHS.UK frontend, the boolean `error: true` prop must be replaced with an error message string:
60+
61+
```patch
62+
<TextInput
63+
label="What is your NHS number?"
64+
labelProps={{ isPageHeading: true, size: 'l' }}
65+
- error
66+
+ error="Enter NHS number"
67+
/>
68+
```
69+
70+
Read about [our guidance on error messages](https://service-manual.nhs.uk/design-system/components/error-message) on the design system in the NHS digital service manual.
71+
5772
### Make sure heading levels are lowercase
5873

5974
If you are using the `headingLevel` prop you will need to update any uppercase values to lowercase:
@@ -298,7 +313,7 @@ After:
298313
To align with NHS.UK frontend, the radios component automatically renders its own fieldset, legend and associated ARIA attributes. You must also rename the `Radios.Radio` component to `Radios.Item` as shown:
299314

300315
```patch
301-
- <Fieldset>
316+
- <Fieldset disableErrorLine="false">
302317
- <Fieldset.Legend>Have you changed your name?</Fieldset.Legend>
303318
- <Radios>
304319
+ <Radios legend="Have you changed your name?">
@@ -310,12 +325,14 @@ To align with NHS.UK frontend, the radios component automatically renders its ow
310325
- </Fieldset>
311326
```
312327

328+
The prop `disableErrorLine` is no longer necessary.
329+
313330
### Checkboxes
314331

315332
To align with NHS.UK frontend, the checkboxes component automatically renders its own fieldset, legend and associated ARIA attributes. You must also rename the `Checkboxes.Box` component to `Checkboxes.Item` as shown:
316333

317334
```patch
318-
- <Fieldset>
335+
- <Fieldset disableErrorLine="false">
319336
- <Fieldset.Legend>What is your nationality?</Fieldset.Legend>
320337
- <Checkboxes>
321338
+ <Checkboxes legend="What is your nationality?">
@@ -336,6 +353,8 @@ You must also rename the `Checkboxes.Item` prop `inputRef` to `ref` for consiste
336353
+ <Checkboxes.Item ref={ref}>Example</Checkboxes.Item>
337354
```
338355

356+
The prop `disableErrorLine` is no longer necessary.
357+
339358
### Error summary
340359

341360
To align with NHS.UK frontend, the error summary component is automatically alerted to screen readers by focusing itself on render. You will need to make the following changes:

src/components/form-elements/checkboxes/__tests__/Checkboxes.test.tsx

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe('Checkboxes', () => {
1616
expect(container).toMatchSnapshot();
1717
});
1818

19-
it('matches snapshot with string error', async () => {
19+
it('matches snapshot with error message', async () => {
2020
const { container } = await renderClient(
2121
<Checkboxes id="example" name="example" error="Example error">
2222
<Checkboxes.Item value="animal">Waste from animal carcasses</Checkboxes.Item>
@@ -29,19 +29,6 @@ describe('Checkboxes', () => {
2929
expect(container).toMatchSnapshot();
3030
});
3131

32-
it('matches snapshot with boolean error', async () => {
33-
const { container } = await renderClient(
34-
<Checkboxes id="example" name="example" error={true}>
35-
<Checkboxes.Item value="animal">Waste from animal carcasses</Checkboxes.Item>
36-
<Checkboxes.Item value="mines">Waste from mines or quarries</Checkboxes.Item>
37-
<Checkboxes.Item value="farm">Farm or agricultural waste</Checkboxes.Item>
38-
</Checkboxes>,
39-
{ moduleName: 'nhsuk-checkboxes' },
40-
);
41-
42-
expect(container).toMatchSnapshot();
43-
});
44-
4532
it('matches snapshot with an exclusive checkbox', async () => {
4633
const { container } = await renderClient(
4734
<Checkboxes id="example" name="example">

src/components/form-elements/checkboxes/__tests__/__snapshots__/Checkboxes.test.tsx.snap

Lines changed: 1 addition & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -316,81 +316,7 @@ exports[`Checkboxes matches snapshot with an exclusive checkbox 1`] = `
316316
</div>
317317
`;
318318

319-
exports[`Checkboxes matches snapshot with boolean error 1`] = `
320-
<div>
321-
<div
322-
class="nhsuk-form-group nhsuk-form-group--error"
323-
>
324-
<div
325-
aria-describedby="example--error-message"
326-
class="nhsuk-checkboxes"
327-
data-module="nhsuk-checkboxes"
328-
data-nhsuk-checkboxes-init=""
329-
id="example"
330-
>
331-
<div
332-
class="nhsuk-checkboxes__item"
333-
>
334-
<input
335-
class="nhsuk-checkboxes__input"
336-
data-checkbox-exclusive-group="example"
337-
id="example-1"
338-
name="example"
339-
type="checkbox"
340-
value="animal"
341-
/>
342-
<label
343-
class="nhsuk-label nhsuk-checkboxes__label"
344-
for="example-1"
345-
id="example-1--label"
346-
>
347-
Waste from animal carcasses
348-
</label>
349-
</div>
350-
<div
351-
class="nhsuk-checkboxes__item"
352-
>
353-
<input
354-
class="nhsuk-checkboxes__input"
355-
data-checkbox-exclusive-group="example"
356-
id="example-2"
357-
name="example"
358-
type="checkbox"
359-
value="mines"
360-
/>
361-
<label
362-
class="nhsuk-label nhsuk-checkboxes__label"
363-
for="example-2"
364-
id="example-2--label"
365-
>
366-
Waste from mines or quarries
367-
</label>
368-
</div>
369-
<div
370-
class="nhsuk-checkboxes__item"
371-
>
372-
<input
373-
class="nhsuk-checkboxes__input"
374-
data-checkbox-exclusive-group="example"
375-
id="example-3"
376-
name="example"
377-
type="checkbox"
378-
value="farm"
379-
/>
380-
<label
381-
class="nhsuk-label nhsuk-checkboxes__label"
382-
for="example-3"
383-
id="example-3--label"
384-
>
385-
Farm or agricultural waste
386-
</label>
387-
</div>
388-
</div>
389-
</div>
390-
</div>
391-
`;
392-
393-
exports[`Checkboxes matches snapshot with string error 1`] = `
319+
exports[`Checkboxes matches snapshot with error message 1`] = `
394320
<div>
395321
<div
396322
class="nhsuk-form-group nhsuk-form-group--error"

src/components/form-elements/date-input/DateInputContext.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { createContext, ChangeEvent } from 'react';
33
export type IDateInputContext = {
44
id: string;
55
name: string;
6-
error: string | boolean | undefined;
6+
error: string | undefined;
77
value?: { day?: string; month?: string; year?: string };
88
defaultValue?: { day?: string; month?: string; year?: string };
99
handleChange: (inputType: 'day' | 'month' | 'year', event: ChangeEvent<HTMLInputElement>) => void;

src/components/form-elements/date-input/__tests__/DateInput.test.tsx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,21 @@ describe('DateInput', () => {
1818
expect(container).toMatchSnapshot();
1919
});
2020

21+
it('matches snapshot with error message', async () => {
22+
const { container } = await renderClient(
23+
<DateInput
24+
hint="For example, 15 3 1984"
25+
legend="What is your date of birth?"
26+
legendProps={{ size: 'l' }}
27+
id="date-input"
28+
error="Date of birth must include a day"
29+
/>,
30+
{ className: 'nhsuk-date-input' },
31+
);
32+
33+
expect(container).toMatchSnapshot();
34+
});
35+
2136
it('matches snapshot with custom date fields', async () => {
2237
const { container } = await renderClient(
2338
<DateInput
@@ -36,6 +51,25 @@ describe('DateInput', () => {
3651
expect(container).toMatchSnapshot();
3752
});
3853

54+
it('matches snapshot with custom date fields and error message', async () => {
55+
const { container } = await renderClient(
56+
<DateInput
57+
hint="For example, 15 3 1984"
58+
legend="What is your date of birth?"
59+
legendProps={{ size: 'l' }}
60+
id="date-input"
61+
error="Date of birth must include a day"
62+
>
63+
<DateInput.Day />
64+
<DateInput.Month defaultValue="3" error={false} />
65+
<DateInput.Year defaultValue="1984" error={false} />
66+
</DateInput>,
67+
{ className: 'nhsuk-date-input' },
68+
);
69+
70+
expect(container).toMatchSnapshot();
71+
});
72+
3973
it('matches snapshot (via server)', async () => {
4074
const { container, element } = await renderServer(
4175
<DateInput

0 commit comments

Comments
 (0)