Skip to content

Commit 1ae2f93

Browse files
Carousel: Ensure safe indexing of carousel on resize edge case (#33732)
1 parent 4f791b3 commit 1ae2f93

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "fix: Ensure carousel handles indexing when window size is larger then combined card size",
4+
"packageName": "@fluentui/react-carousel",
5+
"email": "mifraser@microsoft.com",
6+
"dependentChangeType": "patch"
7+
}

packages/react-components/react-carousel/library/src/components/CarouselNavButton/useCarouselNavButton.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export const useCarouselNavButton_unstable = (
7070

7171
useIsomorphicLayoutEffect(() => {
7272
return subscribeForValues(data => {
73-
const controlList = data.groupIndexList[index];
73+
const controlList = data.groupIndexList?.[index] ?? [];
7474
const _controlledSlideIds = controlList
7575
.map((slideIndex: number) => {
7676
return data.slideNodes[slideIndex].id;

packages/react-components/react-carousel/library/src/components/CarouselNavImageButton/useCarouselNavImageButton.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export const useCarouselNavImageButton_unstable = (
6363

6464
useIsomorphicLayoutEffect(() => {
6565
return subscribeForValues(data => {
66-
const controlList = data.groupIndexList[index];
66+
const controlList = data.groupIndexList?.[index] ?? [];
6767
const _controlledSlideIds = controlList
6868
.map((slideIndex: number) => {
6969
return data.slideNodes[slideIndex].id;

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,9 @@ export function useEmblaCarousel(
150150
const updateIndex = () => {
151151
const newIndex = emblaApi.current?.selectedScrollSnap() ?? 0;
152152
const slides = emblaApi.current?.slideNodes();
153-
const actualIndex = emblaApi.current?.internalEngine().slideRegistry[newIndex][0] ?? 0;
153+
const slideRegistry = emblaApi.current?.internalEngine().slideRegistry;
154+
const actualIndex = slideRegistry?.[newIndex]?.[0] ?? 0;
155+
154156
// We set the first card in the current group as the default tabster index for focus capture
155157
slides?.forEach((slide, slideIndex) => {
156158
setTabsterDefault(slide, slideIndex === actualIndex);

0 commit comments

Comments
 (0)