question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Provide a way to handle slide click and cancel it if mouse is moving

See original GitHub issue

Describe the feature you’d like:

Today, when I’m implement click on slide of this slider. The click is fired when my users slide left or right the carousel. I would like the Slide onClick to be cancel if the user is sliding or best, I would like a way to know when my user is sliding in my child component.

Suggested implementation:

Put what I understand is the var I’m looking for isBeingMouseDragged (in Slider.jsx) in the Context Provider so I can use it in my component with useContext() :

import { SliderContext } from 'pure-react-carousel';

const InnerSlide : React.FC<{ id: string }> = ({ id }) => {
  const { isUserMouseMoving } = useContext(SliderContext);

  const handleClick = useCallback((e) => {
    if (isUserMouseMoving) { e.preventDefault(); return; }

    // handle the click with props id
  }, [isUserMouseMoving, id]); 

  return <div className="inner" onClick={handleClick}> my super inner slide {id}</div>;
};

Describe alternatives you’ve considered:

Add a listener on mouse move, mouse down, mouse up on the whole slider and do it myself. I found it sad as I think it is already done in the pure-react-carousel code.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
azurekcacommented, Jan 28, 2021

Hi, is this issue still being investigated? I am having problems with this as well. I’m using a carousel to display a bunch of products and clicking on a product takes me to the product description. However, I don’t want to navigate away from the page if the carousel is being scrolled.

I see in this commit that stopPropagation was taken out of handleOnClickCapture in Slider.jsx. How about adding another Slider prop to ask developers if they would like to stop event propagation?

0reactions
thomasleduccommented, Nov 16, 2020

Totally agree @mrbinky3000. It was a quick launch, and to be honest we have it on the backlog but did not find a correct way to refactor it. Put the click on the slider would certainly work, even if it is really a shame to have to retrieve the slide clicked and compute a special function for it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Slide Cancel on PC Mouse and Keyboard + Controller ...
This will make you a movement god for verdanks flying over the map like a madman! I hope the COD MW Warzone Movement...
Read more >
Add, change, or remove transitions between slides
Remove a transition · Select the slide that has the transition you want to remove. · On the Transitions tab, in the Transitions...
Read more >
Element: mousemove event - Web APIs | MDN
The mousemove event is fired at an element when a pointing device (usually a mouse) is moved while the cursor's hotspot is inside...
Read more >
Drag'n'Drop with mouse events - The Modern JavaScript Tutorial
Drag'n'Drop is a great interface solution. Taking something and dragging and dropping it is a clear and simple way to do many things, ......
Read more >
Mouse actions and gestures for iPad - Apple Support
Click and hold. Press and hold the mouse. An illustration symbolizing how to use a mouse to drag an item. Drag. Click ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found