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

Fix onDragStart to happen only when dragging/swiping #585

Merged
merged 1 commit into from Sep 9, 2019

Conversation

jflayhart
Copy link
Contributor

@jflayhart jflayhart commented Sep 8, 2019

Description

There is this new prop onDragStart that happens onClick or onTouch 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

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Using the demo and writing a unit test.

Desktop

desktop

Mobile

mobile

@@ -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;
Copy link
Contributor Author

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() {},
Copy link
Contributor Author

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) ...

Copy link
Member

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;
Copy link
Contributor Author

@jflayhart jflayhart Sep 8, 2019

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?

Copy link
Member

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

@sarmeyer sarmeyer merged commit 7f04b8c into FormidableLabs:master Sep 9, 2019
@jflayhart jflayhart deleted the onDragStart-fix branch September 10, 2019 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

onDragStart is invoked prematurely when tapping on a slide
2 participants