Skip to content

Commit

Permalink
Give banner role of 'status' if just an update
Browse files Browse the repository at this point in the history
We currently use the role of 'alert' for all
banners. In recent accessibility testing, the
Digital Accessibility Centre (DAC) suggested we
should only be using that role for important or
time-sensitive updates. This changes the banner
component so the default role is 'status' to
reflect that.

In practice, this will change how the green
banners are announced by screen readers.
  • Loading branch information
tombye committed Feb 27, 2025
1 parent 2fc712d commit ee276b3
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 32 deletions.
2 changes: 1 addition & 1 deletion app/assets/javascripts/esm/focus-banner.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class FocusBanner {

// focus success and error banners when they appear in any content updates
$(document).on("updateContent.onafterupdate", function(evt, el) {
this.focusBanner($(".banner-dangerous, .banner-default-with-tick", el));
this.focusBanner($(".banner-dangerous", el));
}.bind(this));
}

Expand Down
2 changes: 1 addition & 1 deletion app/templates/components/banner.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{% macro banner(body, type=None, with_tick=False, delete_button=None, subhead=None, context=None, action=None, id=None, thing=None) %}
<div
class='banner{% if type %}-{{ type }}{% endif %}{% if with_tick %}-with-tick{% endif %}'
role='alert'
{% if type == 'dangerous' %}role="alert"{% else %}role="status"{% endif %}
{% if id %}
id={{ id }}
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

<div class="ajax-block-container">
{% if verification_status == "pending" %}
<div role="status"></div>
{{ page_header('Checking email reply-to address') }}
<p class="govuk-body">
We’re checking that ‘{{ reply_to_email_address }}’ is a real email address.
Expand All @@ -19,7 +20,6 @@
</p>
{% elif verification_status == "success" %}
{{ banner("‘{}’ is ready to use".format(reply_to_email_address), type='default', with_tick=True) }}

{{ page_header('Checking email reply-to address') }}
<div class="js-stick-at-bottom-when-scrolling">
{{ govukButton({
Expand Down
29 changes: 0 additions & 29 deletions tests/javascripts/focus-banner.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -56,35 +56,6 @@ describe('Focus banner', () => {

});

test('If there is a div.banner-default-with-tick in the updated content, it should be focused', () => {

document.body.innerHTML = `
<div class="ajax-block-container">
</div>`;

const ajaxBlockContainer = document.querySelector('.ajax-block-container');

(new FocusBanner());

ajaxBlockContainer.innerHTML = `
<div class="banner-default-with-tick">
<h2>This is a problem with your upload</h2>
<p>The file uploaded needs to be a PNG</p>
</div>`;

// simulate a content update event
$(document).trigger('updateContent.onafterupdate', ajaxBlockContainer);

const bannerEl = document.querySelector('.banner-default-with-tick');

expect(document.activeElement).toBe(bannerEl);

$(bannerEl).trigger('blur');

expect(bannerEl.hasAttribute('tabindex')).toBe(false);

});

});

});

0 comments on commit ee276b3

Please sign in to comment.