Fix Race Condition if goToSlide is called too early

This commit is contained in:
Patrick McDougle
2024-12-02 14:55:57 -06:00
committed by GitHub
parent 2333e6d697
commit 077bff7832

View File

@@ -506,6 +506,9 @@ export default class SlCarousel extends ShoelaceElement {
}
private scrollToSlide(slide: HTMLElement, behavior: ScrollBehavior = 'smooth') {
// This can happen if goToSlide is called before the scroll container is rendered
// We will have correctly set the activeSlide in goToSlide which will get picked up when initializeSlides is called.
if (!this.scrollContainer) { return; }
const scrollContainer = this.scrollContainer;
const scrollContainerRect = scrollContainer.getBoundingClientRect();
const nextSlideRect = slide.getBoundingClientRect();