mirror of
https://github.com/vercel/commerce.git
synced 2025-03-14 22:42:33 +00:00
fix slider flicker
This commit is contained in:
parent
008d5b17d1
commit
1b3e4e7077
@ -7,11 +7,15 @@ import s from './ProductSlider.module.css'
|
||||
|
||||
const ProductSlider: FC = ({ children }) => {
|
||||
const [currentSlide, setCurrentSlide] = useState(0)
|
||||
const [isMounted, setIsMounted] = useState(false)
|
||||
|
||||
const [ref, slider] = useKeenSlider<HTMLDivElement>({
|
||||
loop: true,
|
||||
slidesPerView: 1,
|
||||
mounted: () => setIsMounted(true),
|
||||
slideChanged(s) {
|
||||
setCurrentSlide(s.details().relativeSlide)
|
||||
},
|
||||
loop: true,
|
||||
})
|
||||
|
||||
return (
|
||||
@ -22,7 +26,11 @@ const ProductSlider: FC = ({ children }) => {
|
||||
<button className={cn(s.rightControl, s.control)} onClick={slider?.next}>
|
||||
<HiChevronRight />
|
||||
</button>
|
||||
<div ref={ref} className="keen-slider h-full">
|
||||
<div
|
||||
ref={ref}
|
||||
className="keen-slider h-full transition-opacity duration-150"
|
||||
style={{ opacity: isMounted ? 1 : 0 }}
|
||||
>
|
||||
{Children.map(children, (child) => {
|
||||
// Add the keen-slider__slide className to children
|
||||
if (isValidElement(child)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user