Skip to content

Commit

Permalink
add support for tab children and carousel
Browse files Browse the repository at this point in the history
hannessolo committed Nov 9, 2023
1 parent d767467 commit ee59ad6
Showing 2 changed files with 25 additions and 9 deletions.
15 changes: 15 additions & 0 deletions blocks/carousel/carousel.js
Original file line number Diff line number Diff line change
@@ -20,4 +20,19 @@ export default function decorate(block) {
buttons.append(button);
});
block.parentElement.append(buttons);

// listener for editor
window.addEventListener('changedSelectedComponent', (e) => {
const element = document.querySelector(e.detail);
if (element.parentElement?.classList.contains('carousel')) {
element.parentElement.scrollTo({ top: 0, left: element.offsetLeft - element.parentNode.offsetLeft, behavior: 'instant' });

const nthSlide = element.offsetLeft / element.parentNode.clientWidth;
const button = block.parentElement.querySelector(`.carousel-buttons > button:nth-child(${nthSlide + 1})`);
[...buttons.children].forEach((r) => r.classList.remove('selected'));
button.classList.add('selected');

window.dispatchEvent(new Event('ue:requestOverlayUpdate'));
}
});
}
19 changes: 10 additions & 9 deletions blocks/tabs/tabs.js
Original file line number Diff line number Diff line change
@@ -95,13 +95,14 @@ export default function decorate($block) {
tab.$content.classList.remove('hidden');
}
});
}

window.addEventListener('changedSelectedComponent', (e) => {
const element = document.querySelector(e.detail);
if (element.classList.contains('tab-item')) {
const index = element.getAttribute('data-tab-index');
const button = document.querySelector(`button[data-tab-index="${index}"]`);
button.click();
}
});
window.addEventListener('ue:changedSelectedComponent', (e) => {
const element = document.querySelector(e.detail);
const tab = element.classList.contains('tab-item') ? element : element.closest('.tab-item');
if (tab) {
const index = tab.getAttribute('data-tab-index');
const button = document.querySelector(`button[data-tab-index="${index}"]`);
button.click();
}
});
}

0 comments on commit ee59ad6

Please sign in to comment.