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

feat: set link title for linked icons to improve accessibility #8

Merged
merged 1 commit into from
Mar 28, 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
5 changes: 4 additions & 1 deletion blocks/footer/footer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getMetadata } from '../../scripts/aem.js';
import { loadFragment } from '../fragment/fragment.js';
import { decorateLangSwitcher } from '../../scripts/scripts.js';
import { decorateLangSwitcher, decorateLinkedIcons } from '../../scripts/scripts.js';

/**
* loads and decorates the footer
Expand All @@ -21,6 +21,9 @@ export default async function decorate(block) {
// language switcher
decorateLangSwitcher(footer.querySelector('ul'));

// set icon name as link title
decorateLinkedIcons(footer.querySelectorAll('a span.icon'));

block.append(footer);

// tag line
Expand Down
5 changes: 4 additions & 1 deletion blocks/header/header.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getMetadata } from '../../scripts/aem.js';
import { loadFragment } from '../fragment/fragment.js';
import { decorateLangSwitcher } from '../../scripts/scripts.js';
import { decorateLangSwitcher, decorateLinkedIcons } from '../../scripts/scripts.js';

// media query match that indicates mobile/tablet width
const isDesktop = window.matchMedia('(min-width: 900px)');
Expand Down Expand Up @@ -145,6 +145,9 @@ export default async function decorate(block) {
// language switcher
decorateLangSwitcher(nav.querySelector('.nav-tools ul'));

// set icon name as link title
decorateLinkedIcons(nav.querySelectorAll('a span.icon'));

const navWrapper = document.createElement('div');
navWrapper.className = 'nav-wrapper';
navWrapper.append(nav);
Expand Down
12 changes: 12 additions & 0 deletions scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ export function decorateLangSwitcher(list) {
}
}

export function decorateLinkedIcons(spanList) {
spanList.forEach((span) => {
const { classList, parentNode } = span;
const iconName = Array.from(classList)
.find((c) => c.startsWith('icon-'))
.substring(5);
if (parentNode.tagName === 'A') {
parentNode.title = iconName;
}
});
}

/**
* Builds hero block and prepends to main in a new section.
* @param {Element} main The container element
Expand Down