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

Adds banner type as ARIA label to banner article elements #346

Draft
wants to merge 11 commits into
base: 1.8.x
Choose a base branch
from

Conversation

danchamp
Copy link
Collaborator

@danchamp danchamp commented Jul 5, 2024

Fixes #345:

  • Sets banner type variable in template_preprocess
  • Changes wrapper element to
    and adds ARIA label and role

@andybroomfield
Copy link
Contributor

@danchamp You can ignore the test fail as it's fixed in 1.8.x. Depending on how soon you need this, you could change the base branch to 1.8.x instead on 1.x and make it part of the refactor work.

@@ -32,7 +32,7 @@
]
%}

<article {{ attributes.addClass(classes) }}>
<article {{ attributes.addClass(classes) }} role="region" aria-label="{{ type_of_alert_label }}">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we intend for this to be a "region" should we remove <article> and replace it with <section>?

It seems strange to have an article element reassigned as a region.

I think MDN agrees with me: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/region_role#prefer_html

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@markconroy Thanks for the pointer, that would make sense and I'll update it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andybroomfield Thanks, I'll move it to 1.8x, it's not urgent so can go with the refactor.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change to article (from div) was made in #123. I'm reading up on MDN Region role which states that the <section> tag is preffered without a aria-role. TBH it's a little confusing as I thought it was best to avoid section if something more suitable was in places (maybe note?

Is the reason to move away from article so you can apply an aria-label for screen readers? Would a span with screen reader text be more approriate, using the Drupal standard of <span class="visually-hidden">label="{{ type_of_alert_label }}</span> be more appropriate?

Should we make the block as a whole a region (aside?)

Copy link
Collaborator Author

@danchamp danchamp Jul 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andybroomfield You're right, if we use <section> then the explicit role is redundant and should be removed. I've updated the template.

The benefit of using an element with an implicit or explicit role is that it makes it a navigational landmark and easier for AT users to be aware of. Example from the demo site with this is place and landmarks listed:

alert-banner-landmarks

<article> has no implicit role, and we'd be relying on users of AT to identify the type of alert by another route - headings perhaps, or by linear access of something like that hidden <span>.

There may be a better way to achieve the aim - a visible label with the alert type maybe? We're currently relying on sighted users to perceive and correctly interpret the colours for each type, so should maybe be more explicit to all users?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the background on implementation, that's helpful

  • I can see the logic in keeping html_id preprocess, reduce risk of forgetting to set html_id in the twig template override.
  • The fact that title is optional was another reason I wanted the type_of_alert_label separate from display_title
  • Alert type being optional as well means makes sense to provide fallback value, such as Announcement, then no risk of landmark just being "region".

Can we just use a single id for the label, even if it means a wrapper around the h2 and the type. <div id="{{ html_id ~ '--label' }}"><h2>{{ title }}</h2><p class="visually-hidden">{{ type_of_alert_label }}</p></div>

Probably viable, although it would need to be outside the {% if display_title %} block.

If navigation is by headers, would we actully need to change this to a region. I'm still feel that the landmark is the alert banner block as a whole, not the indivual banners (and there could be more than one).

The problem, as always, is the versatility of this module, if it was showing 4 "basic" announcements each with a title, then having the block container being <section aria-label="Announcements"> would make sense and be less verbose for screen-reader users navigating by landmarks, as you've said they can navigate by headers within the landmark.
However, if there were 1 "critical" alert, 1 "minor" alert and 2 "announcements" then it seems important that the "critical" alert at least is identified separately.

Maybe a more helpful approach would be:

  • Set block container div to section with aria-label="Announcements"
  • Output the alert type (if set) in the alert banner as agreed above
  • If Alert type: Emergency, then change article to section with aria-labelledby="html_id"

Would a minor alert or death of a notable person warrant being highlighted in landmarks as individual region ?

For the 1.4.1 Use of Color failure, we are agreed that's a bigger change and needs input on what visual mechanism is best or least impactful to implement.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@waako See latest push, though I might now make an accessible label in preprocess instead and set an aria-label instead of a labelled-by.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andybroomfield aria-labelledby is preferred as it references HTML content on the page whereas aria-label is not translatable - not talking about Drupal.t here but via scripts or services (hosted, OS provided or third-party) etc.

I understand why you might want to use preprocess for the accessible label, to keep some logic out of twig template.
However, this brings us back to using 2 IDs for the aria-labelledby, it would simplify the output, and if no title then no ID, therefore ignored and just reads out type_of_alert_label value.

Would this work and appease keeping things in preprocess ?

  • Define alert_title_id and alert_type_label_id in preprocess, so "if title" set alert_title_id to html_id + '--title' else '' (empty string so ignored in aria-labelledby)
  • Update the type_of_alert_label in preprocess to have default Announcement value if type of alert not set

Then it simplifies the twig template logic

{% if display_title %}
    <h2 class="localgov-alert-banner__title" id="{{ alert_title_id }}">
      {{ content.title }}
    </h2> 
 {% endif %}
 <p class="visually-hidden" id="{{ alert_type_label_id }}">{{ type_of_alert_label }}</p>

No need for any wrapping div, and risk of nesting/logic confusion ?
p.s.: Spotted that currently the id="{{ html_id ~ '-label' }}" set both on div and h2

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do we deal with a situation where there is no title and no label?

Screenshot 2024-07-24 at 1 06 15 PM

Copy link
Contributor

@andybroomfield andybroomfield Aug 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Theres also the issue of translation that we need to check.... Not sure how thats going to work becuase these values are part of the field config.

@danchamp danchamp force-pushed the fix/345-add-banner-type-accessible-name branch from e84eddb to 3112e60 Compare July 9, 2024 17:58
@danchamp danchamp changed the base branch from 1.x to 1.8.x July 9, 2024 18:00
@danchamp danchamp requested review from andybroomfield and removed request for msayoung July 9, 2024 18:02
@danchamp danchamp marked this pull request as ready for review July 9, 2024 18:03
@andybroomfield andybroomfield changed the base branch from 1.8.x to 1.8.refactor July 10, 2024 16:11
@andybroomfield andybroomfield deleted the branch 1.8.x July 11, 2024 08:58
@andybroomfield andybroomfield changed the base branch from 1.8.refactor to 1-8-refactor July 11, 2024 09:17
@andybroomfield andybroomfield changed the base branch from 1-8-refactor to 1.8.x July 11, 2024 09:25
@andybroomfield
Copy link
Contributor

@willguv This is the alert banner issue with the missing type of alert label.
If we make a product change, it will be to include either the text of the type of alert or another non-colour way like an icon inside the banner.

@andybroomfield andybroomfield force-pushed the fix/345-add-banner-type-accessible-name branch from 60d305c to 1158070 Compare July 24, 2024 10:32
@andybroomfield
Copy link
Contributor

The test failure here is becuase the label can't be found as the defination is
array(4) { ["00--announcement"]=> string(12) "Announcement" ["20--minor"]=> string(11) "Minor alert" ["50--major"]=> string(9) "Emergency" ["90--notable-person"]=> string(25) "Death of a notable person" }

I think thats the test thats wrong though, although we should correct that as it is possible to set up a type of alert without a label.

@andybroomfield andybroomfield marked this pull request as draft August 6, 2024 10:14
@andybroomfield
Copy link
Contributor

I'm moving this back to draft whilst we continue work on it.

@andybroomfield andybroomfield self-assigned this Aug 6, 2024
danchamp and others added 9 commits August 6, 2024 13:15
Use meaningful ID based on localgov_alert_banner entitiy ID using
Drupal html::unique_id method (will always generate a guranteed unique id).
If there is a title, add it in brackets
Title (Type of alert)

If there is no title, just used the type of alert
Type of alert

If there is a title but no type
Title

If there is no Title or type, translate the string annoucement.
Annoucement|t
- Fix test to refer to minor alert banner key (20--minor)
- Fix template_preprocess to check if type of alert is not empty
- Fix getFieldDefinitions to use the actual alert banner bundle instead of
  the generic localgov_alert_banner
@andybroomfield andybroomfield force-pushed the fix/345-add-banner-type-accessible-name branch from 73f0cad to b4ee0ae Compare August 6, 2024 12:15
@andybroomfield
Copy link
Contributor

Alt is #376 (just show it using manage display).
I'm concerned that the type of alerts are really internal names, and may not be suitable for public display.

@andybroomfield andybroomfield mentioned this pull request Sep 13, 2024
1 task
@andybroomfield
Copy link
Contributor

My instinct is that we maybe should'nt set this here, and this is something a theme should handle, as we don't actully know where someone will place the block. I can see value in wrapping the whole alert banner block in a landmark and using headers for navigation... I do think we need to split this from the colour / label issue which we could do by just including it in manage display as per #376, see my concern about the type of alerts beiing internal names so might need renaming.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Alert banners convey meaning using colour alone by types having styling reflecting their purpose
5 participants