Skip to content

Commit

Permalink
chore(Carousel): show active button on carousel (#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
redxzeta committed Jul 30, 2022
1 parent 1de0ed0 commit 84a2077
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Carousel/Carousel.tsx
Expand Up @@ -54,6 +54,7 @@ const Carousel = forwardRef<HTMLDivElement, CarouselProps>(
)

const [itemRefs, setItemRefs] = useState<RefObject<HTMLDivElement>[]>([])
const [activeIndex, setActiveIndex] = useState(0)

useEffect(() => {
const newRefs: RefObject<HTMLDivElement>[] = []
Expand All @@ -69,6 +70,7 @@ const Carousel = forwardRef<HTMLDivElement, CarouselProps>(
block: 'nearest',
inline: snap,
})
setActiveIndex(index)
}

return (
Expand Down Expand Up @@ -110,7 +112,11 @@ const Carousel = forwardRef<HTMLDivElement, CarouselProps>(
}

return (
<Button key={i} onClick={() => scrollToIndex(i)}>
<Button
active={i === activeIndex}
key={i}
onClick={() => scrollToIndex(i)}
>
{i + 1}
</Button>
)
Expand Down

0 comments on commit 84a2077

Please sign in to comment.