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

MWPW-165969 : Breadcrumb region is missing appropriate roles and/or attributes - Gnav #3521

Open
wants to merge 2 commits into
base: stage
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ const setBreadcrumbSEO = (breadcrumbs) => {
};
breadcrumbs.querySelectorAll('ul > li').forEach((item, idx) => {
const link = item.querySelector('a');
const name = link ? link.innerText.trim() : [...item.childNodes].filter((node) => !node.matches?.('span[aria-hidden="true"]')).map((node) => node.textContent.trim()).join('');
breadcrumbsSEO.itemListElement.push({
'@type': 'ListItem',
position: idx + 1,
name: link ? link.innerText.trim() : item.innerText.trim(),
name,
item: link?.href,
});
});
Expand All @@ -53,8 +54,9 @@ const createBreadcrumbs = (element) => {
.split(',')
.map((item) => item.trim()) || [];

ul.querySelectorAll('li').forEach((li) => {
ul.querySelectorAll('li').forEach((li, index) => {
if (hiddenEntries.includes(li.innerText?.toLowerCase().trim())) li.remove();
if (index > 0) li.insertAdjacentHTML('afterbegin', '<span aria-hidden="true">/</span>');
});

const breadcrumbs = toFragment`
Expand Down
3 changes: 1 addition & 2 deletions libs/blocks/global-navigation/global-navigation.css
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,8 @@ header.global-navigation {
color: var(--feds-color-breadcrumbs--current);
}

.feds-breadcrumbs li:not(:first-of-type)::before {
.feds-breadcrumbs li span[aria-hidden="true"] {
padding: 0 12px;
content: '/';
}

.feds-utilities {
Expand Down
4 changes: 2 additions & 2 deletions test/blocks/global-navigation/features/breadcrumbs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ describe('breadcrumbs', () => {
document.head.innerHTML = '<meta name="breadcrumbs-page-title" content="Custom Title"><meta name="breadcrumbs-show-current-page" content="on">';
const breadcrumb = await breadcrumbs(breadcrumbMock());
assertBreadcrumb({ breadcrumb, length: 5 });
expect(breadcrumb.querySelector('ul li:last-of-type').innerText.trim()).to.equal('Custom Title');
expect(breadcrumb.querySelector('ul li:last-of-type').innerText.trim().replace(/^\//, '').trim()).to.equal('Custom Title');
});

it('should use a custom page title if its explicity set even without breadcrumbs-show-current-page:ON', async () => {
document.head.innerHTML = '<meta name="breadcrumbs-page-title" content="Custom Title">';
const breadcrumb = await breadcrumbs(breadcrumbMock());
assertBreadcrumb({ breadcrumb, length: 5 });
expect(breadcrumb.querySelector('ul li:last-of-type').innerText.trim()).to.equal('Custom Title');
expect(breadcrumb.querySelector('ul li:last-of-type').innerText.trim().replace(/^\//, '').trim()).to.equal('Custom Title');
});

it('should create a breadcrumb SEO element', async () => {
Expand Down
Loading