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

Cannot preventDefault() onDragStart with react-alice-carousel #4

Closed
philippehenoch opened this issue Aug 15, 2018 · 4 comments
Closed

Comments

@philippehenoch
Copy link

My component is use as an item in a react-alice-carousel. When dragging my carousel, I'm trying to prevent Link to be clicked. It seems that using Jelly makes onDragStart event not fired or fired when dragging very quickly. Using a canvas with stroke() makes onDragStart event fired no matter what

import React from 'react';
import Tilt from 'react-tilt';
import { Link } from 'react-router-dom';
import Jelly from 'jelly.js';
import { canvasOptions } from '../../../utils/utils';

class NightySvg extends React.Component {
  componentDidMount() {
    new Jelly(this.canvas.current, canvasOptions('#nightyPath'));
    // const ctx = this.canvas.current.getContext("2d");
    // ctx.beginPath();
    // ctx.moveTo(20,20);
    // ctx.lineTo(20,100);
    // ctx.lineTo(70,100);
    // ctx.stroke();
  }

  canvas = React.createRef();

  handleDrag(e) {
    e.preventDefault();
  }

  render() {
    return (
      <div onDragStart={this.handleDrag}>
        <svg width="289px" height="306px" version="1.1" xmlns="http://www.w3.org/2000/svg" display="none">
          <path id="nightyPath" d="M90.652..." />
        </svg>
        <Link className="menuNav-item" to="/nighty">
          <Tilt className="Tilt" options={{ max: 25 }}>
            <div className="tiltContent">
              <div>
                <span className="menuNumber">01</span>
                <div>nighty</div>
                <canvas draggable="true" ref={this.canvas}
                className="nightyCanvas Tilt-inner" width="289px" height="306px" />
              </div>
            </div>
          </Tilt>
        </Link>
      </div>
    );
  }
}

export default NightySvg;

@lmgonzalves
Copy link
Owner

It seems to be related with event listeners.
I've just made an update. Can you test it?

@philippehenoch
Copy link
Author

It's working well, Thank you!

@philippehenoch
Copy link
Author

@lmgonzalves when the last update will be available on npm?

@lmgonzalves
Copy link
Owner

Sorry, I just forgot to update the npm package.
Updated!

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

No branches or pull requests

2 participants