Skip to content

Commit

Permalink
fix: markup Banner components as regions
Browse files Browse the repository at this point in the history
Banner components are given the region role and an
appropriate label to identify them.

The label is taken from, in order or priority:
- The `iconFallbackText` label, if set
- The type of banner (e.g. "success", "warning", "information")
- The word "banner"

I also removed the visually-hidden insertion
`iconFallbackText` to avoid duplication: if provided, this is
now the region's label.
  • Loading branch information
gregtyler committed May 17, 2022
1 parent 88668d3 commit 0bc5965
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions src/moj/components/banner/template.njk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="moj-banner{% if params.type == 'success' %} moj-banner--success{% elif params.type == 'warning' %} moj-banner--warning{% else %} {{- ' ' + params.classes if params.classes}}{% endif %}" {%- for attribute, value in params.attributes %} {{ attribute }}="{{ value }}"{% endfor %}>
<div class="moj-banner{% if params.type == 'success' %} moj-banner--success{% elif params.type == 'warning' %} moj-banner--warning{% else %} {{- ' ' + params.classes if params.classes}}{% endif %}" {%- for attribute, value in params.attributes %} {{ attribute }}="{{ value }}"{% endfor %} role="region" aria-label="{{ params.iconFallbackText | default(params.type) | default("banner") }}">

{% if params.type == 'success' %}
<svg class="moj-banner__icon" fill="currentColor" role="presentation" focusable="false" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 25 25" height="25" width="25"><path d="M25,6.2L8.7,23.2L0,14.1l4-4.2l4.7,4.9L21,2L25,6.2z"/></svg>
Expand All @@ -10,7 +10,6 @@
{% endif %}

<div class="moj-banner__message">
{% if params.iconFallbackText %}<span class="moj-banner__assistive">{{params.iconFallbackText}}</span>{% endif %}
{{- params.html | safe if params.html else params.text -}}
</div>

Expand Down

0 comments on commit 0bc5965

Please sign in to comment.