Skip to content
Snippets Groups Projects
Commit ec0f2778 authored by shamalainen's avatar shamalainen
Browse files

Add automatic anchor focus

parent 7d765327
No related branches found
No related tags found
No related merge requests found
...@@ -156,6 +156,9 @@ export class AccordionItem { ...@@ -156,6 +156,9 @@ export class AccordionItem {
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 targetElementRect = target.getBoundingClientRect();
window.scrollTo({top: window.scrollY + targetElementRect.top - 200, behavior: 'smooth'});
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];
......
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