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

Exemple for drag handle with images or links #113

Closed
benjamindulau opened this issue Mar 10, 2015 · 4 comments
Closed

Exemple for drag handle with images or links #113

benjamindulau opened this issue Mar 10, 2015 · 4 comments
Labels

Comments

@benjamindulau
Copy link

Hey guys,

Say I have something like the following:

var React = require('react');
var ReactPropTypes = React.PropTypes;
var DragDropMixin = require('react-dnd').DragDropMixin;
var ItemTypes = require('./ItemTypes');

var dragSource = {
    beginDrag: function(component) {
        return {
            item: {
                id: component.props.id
            }
        };
    }
};

var dropTarget = {
    over: function(component, item) {
        component.props.sortFile(item.id, component.props.id);
    }
};

var File = React.createClass({

    mixins: [DragDropMixin],

    propTypes: {
        id:       ReactPropTypes.any.isRequired,
        file:     ReactPropTypes.object.isRequired,
        sortFile: ReactPropTypes.func.isRequired
    },

    statics: {
        configureDragDrop: function(register) {
            register(ItemTypes.FILE, {
                dragSource: dragSource,
                dropTarget: dropTarget
            });
        }
    },

    handleClick: function(e) {
        e.preventDefault();
    },

    render: function() {
        var data = this.props.file;
        var isDragging = this.getDragState(ItemTypes.FILE).isDragging;

        var itemStyle = {
            opacity: isDragging ? 0 : 1
        };

        return (
            <div {...this.dragSourceFor(ItemTypes.FILE)}
                 {...this.dropTargetFor(ItemTypes.FILE)}
                 style={itemStyle}
            >
                <a href="#" onClick={this.handleClick} className="thumbnail">
                    <img src={data.previewUrl} />
                </a>
                <p className="name">
                    {data.name}
                </p>
            </div>
        );
    }

});

module.exports = File;

Drag&Drop works fine when dragging from the paragraph element, but if I start dragging by clicking the anchor element, I can drag but never drop.

How can I fix this? I don't find any example implementing this scenario.

@gaearon
Copy link
Member

gaearon commented Mar 10, 2015

Interesting. Will take a look. My initial guess is in interprets dragging link as “native” link type.

@gaearon gaearon added the bug label Mar 10, 2015
@gaearon
Copy link
Member

gaearon commented Mar 10, 2015

Should be fixed in 0.9.4. Please verify!

@benjamindulau
Copy link
Author

Awesome, works fine. Thanks for being so reactive ;-)

@gaearon
Copy link
Member

gaearon commented Mar 10, 2015

No prob!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants