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 drop if not dragging" (+ page stuck) when DnD quickly #121

Closed
nlevari opened this issue Sep 27, 2017 · 7 comments · Fixed by #125
Closed

"cannot drop if not dragging" (+ page stuck) when DnD quickly #121

nlevari opened this issue Sep 27, 2017 · 7 comments · Fixed by #125
Assignees
Labels

Comments

@nlevari
Copy link

nlevari commented Sep 27, 2017

Bug or feature request?

Bug

Expected behaviour

Drag and Drop will work (or even cancel) for quick drag and drop

Actual behaviour

Dragged element is floating over the entire page (position: fixed) and prevent all click events in page.
This error is written in the console:
"cannot drop if not dragging"
image

Steps to reproduce

Drag and drop quickly several time, you won't need more then 10 seconds.

Browser version

Google chrome 61.0.3163.91 (Official Build) (64-bit)

Demo

dnd bug
Code:

const reorder = (list, startIndex, endIndex) => {
    const result = Array.from(list);
    const [removed] = result.splice(startIndex, 1);
    result.splice(endIndex, 0, removed);

    return result;
};

const grid = 8;

const getListStyle = (isDraggingOver) => ({
    background: isDraggingOver ? '#efefef' : ''
});

const getItemStyle = (draggableStyle, isDragging) => ({
    // some basic styles to make the items look a bit nicer
    // userSelect: isDragging ? 'none' : '',
    padding: grid * 2,
    margin: `0 0 ${grid}px 0`,
    cursor: 'move',

    // change background colour if dragging
    background: isDragging ? '' : '',

    // styles we need to apply on draggables
    ...draggableStyle
});

@observer
export default class CreateMapping extends React.Component {

<-- SOME COMPONENT FUNCTIONS -->
onDragEnd = (result) => {
        // dropped outside the list
        if (!result.destination) {
            return;
        }

        const items = reorder(
            TaskStore.taskData.input.mapping.rules,
            result.source.index,
            result.destination.index
        );
        TaskStore.taskData.input.mapping.rules = items;
    };

    render() {
        let rules = TaskStore.taskData.input.mapping ? TaskStore.taskData.input.mapping.rules : [];
        return (
            <div className="create-mapping">
                <MappingHeaders/>
                <DragDropContext onDragEnd={this.onDragEnd}>
                    <Droppable droppableId="droppable">
                        {(provided, snapshot) => (
                            <div ref={provided.innerRef} style={getListStyle(snapshot.isDraggingOver)}>
                                {rules.map((rule, i) => {
                                    return <Draggable key={i} draggableId={i}>
                                        {(provided, snapshot) => (
                                            <div>
                                                <div ref={provided.innerRef} style={getItemStyle(provided.draggableStyle, snapshot.isDragging)} {...provided.dragHandleProps}>
                                                    <div>
                                                    <MappingRow counter={this.counter} index={i} remove={this.removeDataset} setInitCounter={this.setInitCounter}/>
                                                    </div>
                                                </div>
                                            </div>
                                        )}
                                    </Draggable>
                                })}
                            </div>
                        )}
                    </Droppable>
                </DragDropContext>
                <div className="btn btn-primary" title="Add another mapping to view" onClick={this.addRule}>+</div>
            </div>

        )
    }
@alexreardon
Copy link
Collaborator

Thanks for the bug report. To get a better feel for it can you please create an example on webpack bin. Here is a base to start from: https://www.webpackbin.com/bins/-Kr9aE9jnUeWlphY8wsw

@alexreardon
Copy link
Collaborator

At this stage I am unable to reproduce the issue

@alexreardon
Copy link
Collaborator

In addition to a working example it would be great also to get the steps you use to reproduce the issue - i am following the ones you provided and I cannot reproduce

@nlevari
Copy link
Author

nlevari commented Sep 27, 2017

Hi,
Fortunately it is reproduced in your base webpack bin too.
To reproduce the issue, just click a lot while hovering over one item form left to right to left to right...
Video:
https://drive.google.com/file/d/0B8kvApNkGEh5Y0s0eVJpLXAzYVk/view?usp=drivesdk

Thanks

@alexreardon
Copy link
Collaborator

I suspect this is a timing issue. The drag is being cancelled from within the DROP_COMPLETE (which I did not think could happen!) I want to look into it but i am not around. @jaredcrowe can you take a look?

@alexreardon
Copy link
Collaborator

I suspect this will be a small adjustment

@alexreardon
Copy link
Collaborator

Thanks @nlevari for submitting this - we should be able to resolve it soon

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