Skip to content

Commit

Permalink
fix(carousel): handle infinite scroll with a single child element
Browse files Browse the repository at this point in the history
  • Loading branch information
oyo authored Sep 13, 2024
2 parents f39c355 + 4c2dcbf commit 6a3a2aa
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/components/basic/Carousel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const Carousel = ({
}: CarouselProps) => {
const [showArrows, setShowArrows] = useState(false)
const onMouseEnter = () => {
setShowArrows(true)
setShowArrows(arrayChildren.length > 1)
}
const onMouseLeave = () => {
setShowArrows(false)
Expand Down Expand Up @@ -155,7 +155,9 @@ export const Carousel = ({

const settings = {
dots,
infinite,
// @ref https://github.com/akiran/react-slick/issues/2093#issuecomment-1705213915
// Prevents broken UI by defaulting infinite scroll to false when only a single child element is present.
infinite: infinite && arrayChildren.length > 1,
slidesToShow: responsiveSlides,
slidesToScroll: responsiveSlides,
swipeToSlide: false,
Expand Down

0 comments on commit 6a3a2aa

Please sign in to comment.