Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Click events on clones are not working #74

Open
2 tasks done
baeroe opened this issue Aug 2, 2023 · 6 comments
Open
2 tasks done

Click events on clones are not working #74

baeroe opened this issue Aug 2, 2023 · 6 comments
Labels
bug Something isn't working

Comments

@baeroe
Copy link

baeroe commented Aug 2, 2023

Checks

Version

0.7.12

Description

when you are using the splide with type="loop" then there will be clones of your element on front and end of the slide. Those clones do not fire the click event that is attached on the element.

Screen.Recording.2023-08-02.at.12.53.49.mov

Reproduction Link

https://codesandbox.io/s/react-splide-no-clickevent-on-clone-jfrlnc

Steps to Reproduce

  1. open attached codesandbox
  2. slide the left or right till you have an clone visible in your slider
  3. Press it and watch console for log ( e.g. 'x clicked')

Expected Behaviour

For the clone the event should be fired linke for the original slide. So the clone for the slide with the index 9 should log: "#9 clicked"

@baeroe baeroe added the bug Something isn't working label Aug 2, 2023
@baeroe baeroe changed the title click events on clones are not workting click events on clones are not working Aug 2, 2023
@baeroe baeroe changed the title click events on clones are not working Click events on clones are not working Aug 2, 2023
@chaance
Copy link

chaance commented Aug 24, 2023

Also running into this. Splide uses cloneNode under the hood. I suspect the only way to solve this to cover for all events would be to rewrite the cloning feature in the React port to clone the rendered components instead of the DOM node, since React is responsible for attaching those listeners.

@MaxStetsenko
Copy link

Tried using "rewind", the behavior is slightly different but similar to "Loop". But in 0.7.12 version "rewind" does not work

@austencm
Copy link

austencm commented Sep 8, 2023

I got it working with onClick, which fires whenever a slide is clicked. If you need to have multiple interactive elements inside the slide this may be less helpful tho.

 <Splide onClick={(splide, slide, event) => doSomething()}></Splide>

@jannisstefanis
Copy link

Has there been any solution shared to fix this issue?

@chaance
Copy link

chaance commented Nov 7, 2023

One option that might work (have not explored too deeply) is to write your own Clones component (Splide component, not React component) and use React.cloneElement. Could also be a rabbit hole so who knows. I've found it pretty tricky to get Splide to play well with React.

@markVerb
Copy link

Not using React, but encountered the same issue.
You can try attaching the click handler to the document instead of the element.
For example in jQuery it would be:

$(document).on('click', '.element', function(e){
    // working
});

instead of:

$('.element').on('click', function(e){
    // not working
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants