Skip to content

Commit

Permalink
fix(CarouselBase): fix error when no slides (#7686)
Browse files Browse the repository at this point in the history
* fix(CarouselBase): fix error when no slides

* fix(Gallery): cleanup test
  • Loading branch information
BlackySoul authored and actions-user committed Oct 1, 2024
1 parent 2345d45 commit a0fd632
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ export const CarouselBase = ({
return { coordX: elem.offsetLeft, width: elem.offsetWidth };
}) || [];

if (localSlides.length === 0) {
initialized.current = false;
return;
}

const containerWidth = rootRef.current.offsetWidth;
const viewportOffsetWidth = viewportRef.current.offsetWidth;
const layerWidth = localSlides.reduce((val, slide) => slide.width + val, 0);
Expand All @@ -128,7 +133,7 @@ export const CarouselBase = ({
}
if (remainingWidth <= 0 && slideIndex === localSlides.length) {
warn(
'Ширины слайдов недостаточно для корректной работы свойства "looped". Пожалуйста, сделайте её больше."',
'Ширины слайдов недостаточно для корректной работы свойства "looped". Пожалуйста, сделайте её больше.',
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/vkui/src/components/Gallery/Gallery.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ describe('Gallery', () => {
});

expect(warn).toHaveBeenCalledWith(
'%c[VKUI/Gallery] Ширины слайдов недостаточно для корректной работы свойства "looped". Пожалуйста, сделайте её больше."',
'%c[VKUI/Gallery] Ширины слайдов недостаточно для корректной работы свойства "looped". Пожалуйста, сделайте её больше.',
undefined,
);
warn.mockRestore();
Expand Down

0 comments on commit a0fd632

Please sign in to comment.