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 Breadcrumb component to improve screen reader accessibility #4995

Merged
merged 2 commits into from
Jun 17, 2024
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
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ For advice on how to use these release notes see [our guidance on staying up to

## Unreleased

### Recommended changes

#### Update Breadcrumbs to use `nav` and `aria-label`

We've made changes to the Breadcrumbs component to improve how it appears to screen readers.

We've changed the wrapping element to use the `nav` tag to expose it as a navigational landmark, and added an `aria-label` attribute to differentiate it as breadcrumb navigation.

This change was introduced in [pull request #4995: Update Breadcrumb component to improve screen reader accessibility](https://github.com/alphagov/govuk-frontend/pull/4995).

### Fixes

We've made fixes to GOV.UK Frontend in the following pull requests:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ params:
type: object
required: false
description: HTML attributes (for example data attributes) to add to the breadcrumbs container.
- name: labelText
type: string
required: false
description: Plain text label identifying the landmark to screen readers. Defaults to "Breadcrumb".

examples:
- name: default
Expand Down Expand Up @@ -108,7 +112,7 @@ examples:
options:
attributes:
id: my-navigation
role: navigation
'data-foo': 'bar'
items:
- text: Home
- name: item attributes
Expand All @@ -134,3 +138,13 @@ examples:
- html: <em>Section 1</em>
href: /section-1
- html: <em>Section 2</em>
href: /section-2
- name: custom label
hidden: true
options:
labelText: Briwsion bara
items:
- text: Hafan
href: '/'
- text: Sefydliadau
href: '/organisations'
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ describe('Breadcrumbs', () => {
$listItems = document.querySelectorAll('li.govuk-breadcrumbs__list-item')
})

it('renders as a nav element', () => {
expect($component.tagName.toLowerCase()).toBe('nav')
})

it('renders with default aria-label', () => {
expect($component).toHaveAttribute('aria-label', 'Breadcrumb')
})

it('includes an ordered list', () => {
expect($component).toContainElement($list)
})
Expand Down Expand Up @@ -152,7 +160,14 @@ describe('Breadcrumbs', () => {

const $component = document.querySelector('.govuk-breadcrumbs')
expect($component).toHaveAttribute('id', 'my-navigation')
expect($component).toHaveAttribute('role', 'navigation')
expect($component).toHaveAttribute('data-foo', 'bar')
})

it('renders with a custom aria-label', () => {
document.body.innerHTML = render('breadcrumbs', examples['custom label'])

const $component = document.querySelector('.govuk-breadcrumbs')
expect($component).toHaveAttribute('aria-label', 'Briwsion bara')
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
{% set classNames = classNames + " govuk-breadcrumbs--collapse-on-mobile" %}
{% endif -%}

<div class="{{ classNames }}" {{- govukAttributes(params.attributes) }}>
<nav class="{{ classNames }}" {{- govukAttributes(params.attributes) }} aria-label="{{ params.labelText | default("Breadcrumb") }}">
<ol class="govuk-breadcrumbs__list">
{% for item in params.items %}
{% if item.href %}
Expand All @@ -27,4 +27,4 @@
{% endif %}
{% endfor %}
</ol>
</div>
</nav>
Loading