Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update error messages to use paragraph tags instead of spans #2452

Merged
merged 3 commits into from
Dec 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ If you're importing JavaScript modules individually, you should check any refere

This change was introduced in [pull request #2426: Rename exported JavaScript modules to include component name](https://github.com/alphagov/govuk-frontend/pull/2426).

#### Update the HTML for error messages

We’ve updated the HTML for the error message component to use a paragraph element instead of a span element, as this is more semantically correct.

If you’re not using Nunjucks macros, swap the `<span class="govuk-error-message">` for a `<p class="govuk-error-message">`.

This change was introduced in [pull request #2452: Update error messages to use paragraph tags instead of spans](https://github.com/alphagov/govuk-frontend/pull/2452).

#### Update the HTML for hints

In GOV.UK Frontend v3.8.0, we [updated the HTML for hints to use a `<div>` rather than a `<span>` element, to allow the use of block elements](https://github.com/alphagov/govuk-frontend/issues/1835). We've now removed the styles which made the hint `<span>` display as block.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ exports[`Character count when it includes a hint renders with hint 1`] = `
`;

exports[`Character count when it includes an error message renders with error message 1`] = `
<span id="exceeding-characters-error"
class="govuk-error-message"
<p id="exceeding-characters-error"
class="govuk-error-message"
>
Please do not exceed the maximum allowed limit
</span>
</p>
`;

exports[`Character count with dependant components renders with label 1`] = `
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ exports[`Checkboxes when they include a hint renders the hint 1`] = `
`;

exports[`Checkboxes when they include an error message renders the error message 1`] = `
<span id="waste-error"
class="govuk-error-message"
<p id="waste-error"
class="govuk-error-message"
>
Please select an option
</span>
</p>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ exports[`Date input when it includes a hint renders the hint 1`] = `
`;

exports[`Date input when it includes an error message renders the error message 1`] = `
<span id="dob-errors-error"
class="govuk-error-message"
<p id="dob-errors-error"
class="govuk-error-message"
>
Error message goes here
</span>
</p>
`;
1 change: 1 addition & 0 deletions src/govuk/components/error-message/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
@include govuk-font($size: 19, $weight: bold);

display: block;
margin-top: 0; // Reset any default browser margins for paragraphs
margin-bottom: govuk-spacing(3);
clear: both;

Expand Down
4 changes: 2 additions & 2 deletions src/govuk/components/error-message/template.njk
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% set visuallyHiddenText = params.visuallyHiddenText | default("Error") -%}

<span {%- if params.id %} id="{{ params.id }}"{% endif %} class="govuk-error-message{%- if params.classes %} {{ params.classes }}{% endif %}" {%- for attribute, value in params.attributes %} {{ attribute }}="{{ value }}"{% endfor -%}>
<p {%- if params.id %} id="{{ params.id }}"{% endif %} class="govuk-error-message{%- if params.classes %} {{ params.classes }}{% endif %}" {%- for attribute, value in params.attributes %} {{ attribute }}="{{ value }}"{% endfor -%}>
{% if visuallyHiddenText %}<span class="govuk-visually-hidden">{{ visuallyHiddenText }}:</span> {% endif -%}
{{ params.html | safe if params.html else params.text }}
</span>
</p>
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ exports[`File upload when it includes a hint renders with hint 1`] = `
`;

exports[`File upload when it includes an error message renders with error message 1`] = `
<span id="file-upload-with-error-error"
class="govuk-error-message"
<p id="file-upload-with-error-error"
class="govuk-error-message"
>
Error message
</span>
</p>
`;

exports[`File upload with dependant components renders with label 1`] = `
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ exports[`Input when it includes a hint renders the hint 1`] = `
`;

exports[`Input when it includes an error message renders the error message 1`] = `
<span id="input-with-error-message-error"
class="govuk-error-message"
<p id="input-with-error-message-error"
class="govuk-error-message"
>
Error message goes here
</span>
</p>
`;

exports[`Input with dependant components renders with label 1`] = `
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ exports[`Radios when they include a hint renders the hint 1`] = `
`;

exports[`Radios when they include an error message renders the error message 1`] = `
<span id="example-error-message-error"
class="govuk-error-message"
<p id="example-error-message-error"
class="govuk-error-message"
>
Please select an option
</span>
</p>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ exports[`Select when it includes a hint renders the hint 1`] = `
`;

exports[`Select when it includes an error message renders with error message 1`] = `
<span id="select-with-error-error"
class="govuk-error-message"
<p id="select-with-error-error"
class="govuk-error-message"
>
Error message
</span>
</p>
`;

exports[`Select with dependant components renders with label 1`] = `
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ exports[`Textarea when it includes a hint renders with hint 1`] = `
`;

exports[`Textarea when it includes an error message renders with error message 1`] = `
<span id="no-ni-reason-error"
class="govuk-error-message"
<p id="no-ni-reason-error"
class="govuk-error-message"
>
You must provide an explanation
</span>
</p>
`;

exports[`Textarea with dependant components renders with label 1`] = `
Expand Down