Skip to content

Commit 3d4bb16

Browse files
authored
Carousel - fix initial page (#2059)
1 parent 337ae67 commit 3d4bb16

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/components/carousel/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ class Carousel extends Component<CarouselProps, CarouselState> {
228228
return index;
229229
}
230230

231+
// TODO: currently this returns pagesCount offsets, not starting from 0; look into changing this into (pagesCount - 1) or to have the 1st item as 0
231232
getSnapToOffsets = (): number[] | undefined => {
232233
const {containerWidth, pageWidth} = this.state;
233234

@@ -251,7 +252,7 @@ class Carousel extends Component<CarouselProps, CarouselState> {
251252
const {initialOffset} = this.state;
252253
let contentOffset = initialOffset;
253254
if (snapToOffsets && initialPage !== undefined) {
254-
const offset = snapToOffsets[initialPage];
255+
const offset = initialPage === 0 ? 0 : snapToOffsets[initialPage - 1];
255256
contentOffset = {
256257
x: horizontal ? offset : 0,
257258
y: horizontal ? 0 : offset

0 commit comments

Comments
 (0)