Skip to content

Commit 7f94027

Browse files
committed
fix: getCurrentIndex returns wrong value when data count is < 3
fix #299
1 parent 7a82994 commit 7f94027

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/hooks/useCarouselController.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import type {
1212
TCarouselProps,
1313
WithTimingAnimation,
1414
} from "../types";
15-
import { convertToSharedIndex } from "../utils/computedWithAutoFillData";
15+
import { computedRealIndexWithAutoFillData, convertToSharedIndex } from "../utils/computedWithAutoFillData";
1616
import { dealWithAnimation } from "../utils/dealWithAnimation";
1717
import { handlerOffsetDirection } from "../utils/handlerOffsetDirection";
1818
import { round } from "../utils/log";
@@ -118,8 +118,15 @@ export function useCarouselController(options: IOpts): ICarouselController {
118118
);
119119

120120
const getCurrentIndex = React.useCallback(() => {
121-
return index.value;
122-
}, [index]);
121+
const realIndex = computedRealIndexWithAutoFillData({
122+
index: index.value,
123+
dataLength: dataInfo.originalLength,
124+
loop,
125+
autoFillData: autoFillData!,
126+
});
127+
128+
return realIndex;
129+
}, [index, autoFillData, dataInfo, loop]);
123130

124131
const canSliding = React.useCallback(() => {
125132
return !dataInfo.disable;

0 commit comments

Comments
 (0)