fix(ui): clamp text loop index (#1221)

* fix(ui): clamp text loop index

* fix(ui): report clamped text loop index

---------

Co-authored-by: Isaac Sanchez <isanchez-hawkins@arize.com>
This commit is contained in:
Isaac Sanchez-Hawkins
2026-05-12 11:00:02 +03:00
committed by GitHub
co-authored by Isaac Sanchez
parent da690b67a3
commit e0ef318751
+17 -1
View File
@@ -35,7 +35,23 @@ export function TextLoop({
const items = Children.toArray(children);
useEffect(() => {
if (!trigger) return;
let next = currentIndex;
if (items.length === 0) {
next = 0;
} else if (!Number.isInteger(currentIndex) || currentIndex < 0) {
next = 0;
} else if (currentIndex >= items.length) {
next = items.length - 1;
}
if (next !== currentIndex) {
setCurrentIndex(next);
onIndexChange?.(next);
}
}, [currentIndex, items.length, onIndexChange]);
useEffect(() => {
if (!trigger || items.length <= 1) return;
const intervalMs = interval * 1000;
const timer = setInterval(() => {