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:
committed by
GitHub
co-authored by
Isaac Sanchez
parent
da690b67a3
commit
e0ef318751
@@ -35,7 +35,23 @@ export function TextLoop({
|
|||||||
const items = Children.toArray(children);
|
const items = Children.toArray(children);
|
||||||
|
|
||||||
useEffect(() => {
|
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 intervalMs = interval * 1000;
|
||||||
const timer = setInterval(() => {
|
const timer = setInterval(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user