Skip to content

Commit

Permalink
Adding aria-label for checkout-link using productFamily as placeholde…
Browse files Browse the repository at this point in the history
…r key
  • Loading branch information
seanchoi-dev committed Jan 22, 2025
1 parent f62be2e commit 9f96bd7
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions libs/blocks/merch-card/merch-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -706,10 +706,17 @@ export default async function init(el) {
}
el.replaceWith(merchCard);
decorateMerchCardLinkAnalytics(merchCard);

// Adding aria-label for checkout-link using productFamily as placeholder key
const ctaLink = ctas?.querySelector('a');
if (merchCard.name && ctaLink) {
if (ctaLink && !ctaLink.getAttribute('aria-label')) {
const { replaceKey } = await import('../../features/placeholders.js');
await replaceKey(merchCard.name, getConfig()).then((key) => ctaLink.setAttribute('aria-label', `${ctaLink.textContent} ${key}`));
ctaLink.addEventListener('mas:resolved', async () => {
const productName = ctaLink.value[0]?.productArrangement?.productFamily;
if (productName) {
await replaceKey(productName, getConfig()).then((key) => ctaLink.setAttribute('aria-label', `${ctaLink.textContent} - ${key}`));
}

Check warning on line 718 in libs/blocks/merch-card/merch-card.js

View check run for this annotation

Codecov / codecov/patch

libs/blocks/merch-card/merch-card.js#L715-L718

Added lines #L715 - L718 were not covered by tests
});
}
return merchCard;
}

0 comments on commit 9f96bd7

Please sign in to comment.