fix(dashboard-v2): fix slider scrolling to far when window size is increased on the last slide

This commit is contained in:
Michał Leszczyk 2022-02-26 12:25:01 +01:00
parent 92892bf2d2
commit 7adbc4bf68
No known key found for this signature in database
GPG Key ID: FA123CA8BAA2FBF4
1 changed files with 9 additions and 0 deletions

View File

@ -38,6 +38,15 @@ const Slider = ({ slides, breakpoints }) => {
[slides, visibleSlides, setActiveIndex] [slides, visibleSlides, setActiveIndex]
); );
React.useEffect(() => {
const maxIndex = slides.length - visibleSlides;
// Make sure to not scroll too far when screen size changes.
if (activeIndex > maxIndex) {
setActiveIndex(maxIndex);
}
}, [slides.length, visibleSlides, activeIndex]);
return ( return (
<Container> <Container>
<Scroller <Scroller