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

Added Analytics Attributes to Tabs and Tabpanels #3275

Merged
merged 2 commits into from
Nov 28, 2024
Merged
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
15 changes: 10 additions & 5 deletions libs/blocks/global-navigation/utilities/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,16 +418,19 @@ export const [setUserProfile, getUserProfile] = (() => {

export const transformTemplateToMobile = async (popup, item, localnav = false) => {
const notMegaMenu = popup.parentElement.tagName === 'DIV';
if (notMegaMenu) return;
if (notMegaMenu) return null;

const originalContent = popup.innerHTML;
const tabs = [...popup.querySelectorAll('.feds-menu-section')]
.filter((section) => !section.querySelector('.feds-promo') && section.textContent)
.map((section) => {
const name = section.querySelector('.feds-menu-headline')?.textContent ?? 'Shop For';
const headline = section.querySelector('.feds-menu-headline');
const name = headline?.textContent ?? 'Shop For';
const daallTab = headline?.getAttribute('daa-ll');
const daalhTabContent = section.querySelector('.feds-menu-items')?.getAttribute('daa-lh');
const content = section.querySelector('.feds-menu-items') ?? section;
const links = [...content.querySelectorAll('a.feds-navLink')].map((x) => x.outerHTML).join('');
return { name, links };
return { name, links, daallTab, daalhTabContent };
});
const CTA = popup.querySelector('.feds-cta')?.outerHTML ?? '';
const mainMenu = `
Expand All @@ -453,21 +456,23 @@ export const transformTemplateToMobile = async (popup, item, localnav = false) =
<h7>${item.textContent.trim()}</h7>
</div>
<div class="tabs" role="tablist">
${tabs.map(({ name }, i) => `
${tabs.map(({ name, daallTab }, i) => `
<button
role="tab"
class="tab"
aria-selected="false"
aria-controls="${i}"
${daallTab ? `daa-ll="${daallTab}"` : ''}
>${name}</button>
`).join('')}
</div>
<div class="tab-content">
${tabs.map(({ links }, i) => `
${tabs.map(({ links, daalhTabContent }, i) => `
<div
id="${i}"
role="tabpanel"
aria-labelledby="${i}"
${daalhTabContent ? `daa-lh="${daalhTabContent}"` : ''}
hidden
>
${links}
Expand Down
Loading