Skip to content
Snippets Groups Projects
Commit aa5580eb authored by Ekaterina Kondareva's avatar Ekaterina Kondareva
Browse files

check if anchor link exists on the page

parent 0c641d03
No related branches found
No related tags found
No related merge requests found
...@@ -130,17 +130,19 @@ export class AccordionItem { ...@@ -130,17 +130,19 @@ export class AccordionItem {
if (anchor.length > 0) { if (anchor.length > 0) {
anchor = anchor.substr(1); anchor = anchor.substr(1);
let target = document.querySelectorAll(`[id=${anchor}]`)[0]; let target = document.querySelectorAll(`[id=${anchor}]`)[0];
let targetParent = target.closest('.hy-accordion__item'); if (target) {
let targetContent = targetParent.querySelectorAll('.hy-accordion__content')[0]; let targetParent = target.closest('.hy-accordion__item');
let targetContent = targetParent.querySelectorAll('.hy-accordion__content')[0];
this.expandSection(targetContent); this.expandSection(targetContent);
target.setAttribute('aria-expanded', 'true'); target.setAttribute('aria-expanded', 'true');
targetParent.classList.add('hy-accordion__item__is-open'); targetParent.classList.add('hy-accordion__item__is-open');
const containerId = targetParent.parentElement.parentElement.id; const containerId = targetParent.parentElement.parentElement.id;
if (containerId.length > 0) { if (containerId.length > 0) {
let accordion = document.querySelectorAll(`#${containerId}`)[0]; let accordion = document.querySelectorAll(`#${containerId}`)[0];
accordion.querySelector(`#${target.getAttribute('aria-controls')}`).setAttribute('aria-hidden', 'false'); accordion.querySelector(`#${target.getAttribute('aria-controls')}`).setAttribute('aria-hidden', 'false');
}
} }
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment