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
Fix onDragStart to happen only when dragging/swiping #585
Conversation
@@ -279,6 +275,11 @@ export default class Carousel extends React.Component { | |||
) | |||
); | |||
|
|||
if (length >= 10) { | |||
if (this.clickDisabled === false) this.props.onDragStart(e); | |||
this.clickDisabled = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably should have disabled click here anyway, which prevents unwanted click events from firing during swiping on touch devices!
@@ -1181,6 +1181,7 @@ Carousel.defaultProps = { | |||
framePadding: '0px', | |||
height: 'auto', | |||
heightMode: 'max', | |||
onDragStart() {}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added default prop to avoid guards everywhere of if (this.props.onDragStart) ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks!
if (length >= 10) this.clickDisabled = true; | ||
if (length >= 10) { | ||
if (this.clickDisabled === false) this.props.onDragStart(e); | ||
this.clickDisabled = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sarmeyer I don't love coupling these two together (disable click + drag start), but it works and somewhat related. Any better ideas?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't think of anything right now, we can leave this in until I (or someone else with time) has time to figure out another solution
Description
There is this new prop
onDragStart
that happensonClick
oronTouch
rather than an actual drag/swipe event. I modified the code slightly to make the behavior more appropriate to the event. It is better to do it this way so the event doesn't give a false impression that it is starting a drag event when only a click occurs.Fixes #579
Type of Change
How Has This Been Tested?
Using the demo and writing a unit test.
Desktop
Mobile