Splidejs / react-splide

The React component for the Splide slider/carousel.
https://splidejs.com/
MIT License
233 stars 57 forks source link

Issue when using React Splide in Material tailwind library #69

Open Sergey98Am opened 1 year ago

Sergey98Am commented 1 year ago

Checks

Version

0.7.12

Description

I use React Splide in Material Tailwind library's modal dialog. I need to synchronize the main and thumbnail sliders, but in useEffect hook the sync() function doesn't work. The same issue also occurs when using the Headless UI library's modal instead of Material Tailwind (When the modal is built manually without the library,the sync works)

Reproduction Link

No response

Steps to Reproduce

  1. npm i @splidejs/react-splide@0.7.12
  2. npm i @material-tailwind/react
    
    import { useEffect, createRef, Fragment, useState } from "react";
    import { Dialog, Button } from "@material-tailwind/react";
    import { Splide, SplideSlide } from "@splidejs/react-splide";

export default function App() { const [open, setOpen] = useState(false);

const handleOpen = () => setOpen(!open);

/**

Expected Behaviour

I need the sync() function to work in useEffect when using the Material Tailwind library

deepakrh185 commented 1 year ago

Hi @Sergey98Am I will work on this, kindly assigne it to me.

Sergey98Am commented 1 year ago

Hi @deepakrh185․ Thanks for responding

deepakrh185 commented 1 year ago

Hi @deepakrh185․ Thanks for responding

kindly assigne the bug to me @Sergey98Am

deepakrh185 commented 1 year ago

@Sergey98Am try to add useEffect(() => { if (mainRef.current && thumbsRef.current && thumbsRef.current.splide) { mainRef.current.sync(thumbsRef.current.splide); } }, [open]);

check it works or not !!

Sergey98Am commented 1 year ago

@deepakrh185. Tried it, unfortunately, it didn't work

deepakrh185 commented 1 year ago

@Sergey98Am can you brief me the scenario what it exactly happens?

Sergey98Am commented 1 year ago

@deepakrh185. Clicking the thumbnails slider doesn't change the main slider at the same time material-tailwind-splide.webm

noneex commented 1 month ago

@Sergey98Am I've got similar problem. In my case I have thumbnails on a page and detail view in a dialog. Fixed it by the following workaround:

<Splide
  ref={(mainRefNode) => {
      if (!mainRefNode) return;

      setTimeout(() => {
          mainRefNode.sync(thumbsRef.current.splide);
          mainRefNode.go(thumbsRef.current.splide.index); // calling "go" here since "sync" doesn't go to appropriate slide
      }, 0);
  }}
  ...
  >... </Splide>