Skip to content

Commit 3d2e4f6

Browse files
Carousel: Enable dynamic autoplayInterval (microsoft#34142)
1 parent 8cd77a6 commit 3d2e4f6

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "Stop and reinitialize autoplay on carousel when autoplay interval changes",
4+
"packageName": "@fluentui/react-carousel",
5+
"email": "mifraser@microsoft.com",
6+
"dependentChangeType": "patch"
7+
}

packages/react-components/react-carousel/library/src/components/useEmblaCarousel.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@ export function useEmblaCarousel(
229229
// Use direct viewport if available, else fallback to container (includes Carousel controls).
230230
currentElement = viewportRef.current ?? newElement;
231231
if (currentElement) {
232+
// Stop autoplay before reinitializing.
233+
emblaApi.current?.plugins?.().autoplay?.stop();
232234
emblaApi.current = EmblaCarousel(
233235
currentElement,
234236
{
@@ -291,6 +293,8 @@ export function useEmblaCarousel(
291293
duration: motionDuration,
292294
};
293295

296+
// Stop autoplay before reinitializing.
297+
emblaApi.current?.plugins?.().autoplay?.stop();
294298
emblaApi.current?.reInit(
295299
{
296300
...DEFAULT_EMBLA_OPTIONS,

0 commit comments

Comments
 (0)