Fix init/select out of sync issues.

This commit is contained in:
Dermot Duffy
2023-09-05 20:39:54 -07:00
parent 25150be36b
commit 1a4d38e609
4 changed files with 27 additions and 22 deletions
+5 -5
View File
@@ -137,10 +137,11 @@ export class CarouselController {
);
const getCarouselSelectedObject = (): CarouselSelected | null => {
const selectedIndex = this.getSelectedIndex();
const slide = this.getSlide(selectedIndex);
if (selectedIndex !== null && slide) {
// Caution: Must use methods/accessors of the new carousel, not the public
// API of this controller which may use a different carousel.
const selectedIndex = carousel.selectedScrollSnap();
const slide = carousel.slideNodes()[selectedIndex] ?? null;
if (slide) {
return {
index: selectedIndex,
element: slide,
@@ -160,7 +161,6 @@ export class CarouselController {
}
};
carousel.on('init', () => selectSlide());
carousel.on('select', () => selectSlide());
carousel.on('settle', () => {
const carouselSelected = getCarouselSelectedObject();