[Help]: selectedScrollSnap() doesn't return indexes for some snaps #1023
-
SummaryI have a carousell with slides the same as my viewport and I want to get the index of the selected slide. So selectedScrollSnap should work on this and return the index of the selected slide. But it does it only for the first second and last slides depending on what direction you were sliding for some reason. I Don't know what causes this because I use the same function on another bit different carousell and it works flawlessly. Here is a codesandbox example: If applicable, which variants of Embla Carousel are relevant to this question?
Additional informationI am using "embla-carousel-react": "^8.1.7", and the only difference I can see between the working and the non working carousell is that the non working one has prev and next buttons and some different styles CodeSandbox example |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @Wakinki, Thanks for your question. In your code,
|
Beta Was this translation helpful? Give feedback.
Hi @Wakinki,
Thanks for your question. In your code,
selectedScrollSnap
will only update when your component re-renders. What you want to do is the same thing as the dot button file, in one of the examples on the documentation page that has dots. For example, the default example:EmblaCarouselDotButton
file.selectedIndex
is used.