From dc1e558ba70391e0fbbd7c78e8d90024cd73ff98 Mon Sep 17 00:00:00 2001 From: beeps Date: Mon, 20 May 2024 13:26:03 +0100 Subject: [PATCH] Change breadcrumb component to use nav element --- .../components/breadcrumbs/breadcrumbs.yaml | 16 +++++++++++++++- .../breadcrumbs/template.jsdom.test.js | 17 ++++++++++++++++- .../govuk/components/breadcrumbs/template.njk | 4 ++-- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/packages/govuk-frontend/src/govuk/components/breadcrumbs/breadcrumbs.yaml b/packages/govuk-frontend/src/govuk/components/breadcrumbs/breadcrumbs.yaml index 9572b1e4c4..3caa13207f 100644 --- a/packages/govuk-frontend/src/govuk/components/breadcrumbs/breadcrumbs.yaml +++ b/packages/govuk-frontend/src/govuk/components/breadcrumbs/breadcrumbs.yaml @@ -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 @@ -108,7 +112,7 @@ examples: options: attributes: id: my-navigation - role: navigation + 'data-foo': 'bar' items: - text: Home - name: item attributes @@ -134,3 +138,13 @@ examples: - html: Section 1 href: /section-1 - html: Section 2 + href: /section-2 + - name: custom label + hidden: true + options: + labelText: Briwsion bara + items: + - text: Hafan + href: '/' + - text: Sefydliadau + href: '/organisations' diff --git a/packages/govuk-frontend/src/govuk/components/breadcrumbs/template.jsdom.test.js b/packages/govuk-frontend/src/govuk/components/breadcrumbs/template.jsdom.test.js index 12e9a02f04..211d58bde0 100644 --- a/packages/govuk-frontend/src/govuk/components/breadcrumbs/template.jsdom.test.js +++ b/packages/govuk-frontend/src/govuk/components/breadcrumbs/template.jsdom.test.js @@ -18,6 +18,14 @@ describe('Breadcrumbs', () => { $listItems = document.querySelectorAll('li.govuk-breadcrumbs__list-item') }) + it('renders as a nav element', () => { + expect($component.tagName).toBe('nav') + }) + + it('renders with default aria-label', () => { + expect($component).toHaveAttribute('aria-label', 'Breadcrumb') + }) + it('includes an ordered list', () => { expect($component).toContainElement($list) }) @@ -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') }) }) }) diff --git a/packages/govuk-frontend/src/govuk/components/breadcrumbs/template.njk b/packages/govuk-frontend/src/govuk/components/breadcrumbs/template.njk index 1fad1b7431..b6d0942863 100644 --- a/packages/govuk-frontend/src/govuk/components/breadcrumbs/template.njk +++ b/packages/govuk-frontend/src/govuk/components/breadcrumbs/template.njk @@ -11,7 +11,7 @@ {% set classNames = classNames + " govuk-breadcrumbs--collapse-on-mobile" %} {% endif -%} -
+
+