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

🐛 fix(header): corrige la duplication des collapses dans le menu mobile [DS-3680] #873

Merged
merged 2 commits into from
Jan 30, 2024
Merged
Changes from 1 commit
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
16 changes: 15 additions & 1 deletion src/component/header/script/header/header-links.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,22 @@ class HeaderLinks extends api.core.Instance {
const toolsHtml = this.toolsLinks.innerHTML.replace(/ +/g, ' ');
const menuHtml = this.menuLinks.innerHTML.replace(/ +/g, ' ');
// Pour éviter de dupliquer des id, on ajoute un suffixe aux id et aria-controls duppliqués.
let toolsHtmlIdList = toolsHtml.match(/id="(.*?)"/gm);
if (toolsHtmlIdList) {
// on a besoin d'échapper les backslash dans la chaine de caractère
// eslint-disable-next-line no-useless-escape
toolsHtmlIdList = toolsHtmlIdList.map(element => element.replace('id=\"', '').replace('\"', ''));
}
const toolsHtmlAriaControlList = toolsHtml.match(/aria-controls="(.*?)"/gm);
let toolsHtmlDuplicateId = toolsHtml.replace(/id="(.*?)"/gm, 'id="$1' + copySuffix + '"');
toolsHtmlDuplicateId = toolsHtmlDuplicateId.replace(/(<nav[.\s\S]*-translate [.\s\S]*) aria-controls="(.*?)"([.\s\S]*<\/nav>)/gm, '$1 aria-controls="$2' + copySuffix + '"$3');
if (toolsHtmlAriaControlList) {
for (const element of toolsHtmlAriaControlList) {
const ariaControlsValue = element.replace('aria-controls="', '').replace('"', '');
if (toolsHtmlIdList.includes(ariaControlsValue)) {
toolsHtmlDuplicateId = toolsHtmlDuplicateId.replace(`aria-controls="${ariaControlsValue}"`, `aria-controls="${ariaControlsValue + copySuffix}"`);
};
}
}

if (toolsHtmlDuplicateId === menuHtml) return;

Expand Down