Event trigger("dragstart") without dataTransfer
See original GitHub issue- Operating System: Linux
- Cypress Version: 0.20.0
Is this a Feature or Bug?
Bug
Current behavior:
It seems that after trigger the dragstart event. The generated event for handling function is type of Event not DragEvent. The event parameter is without dataTransfer method.
Desired behavior:
Provide the event handler with DragEvent not just only Event type of object.
How to reproduce:
Test code:
<!DOCTYPE HTML>
<html>
<head>
<script>
function allowDrop(ev) {
ev.preventDefault();
}
function drag(ev) {
// THERE SHOULD BE DragEvent not only Event
console.log('EV: ', ev);
ev.dataTransfer.setData("text", ev.target.id); // This die
}
function drop(ev) {
ev.preventDefault();
var data = ev.dataTransfer.getData("text");
ev.target.appendChild(document.getElementById(data));
}
</script>
</head>
<body>
<div id="div1" ondrop="drop(event)" ondragover="allowDrop(event)" width="200px" height="200px" style="border: 1px solid red">DROP</div>
<div id="drag1" draggable="true"
ondragstart="drag(event)" width="100px" height="80px">DRAG</div>
</body>
</html>
Test:
describe('Drag test html5', function() {
it('main', function() {
cy.visit('http://localhost:8080/');
cy.get('#drag1').trigger("dragstart");
})
})
Additional Info (images, stack traces, etc)
Event from Cypress.io: EV: Event {isTrusted: false, clientX: 500, clientY: 16, pageX: 500, pageY: 16…} Event from browser: EV: DragEvent {isTrusted: true, dataTransfer: DataTransfer, screenX: 668, screenY: 133, clientX: 34…}
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:11 (6 by maintainers)
Top Results From Across the Web
Drag operations - Web APIs - MDN Web Docs - Mozilla
Within the dragstart event, you can specify the drag data, the feedback image, and the drag effects, all of which are described below....
Read more >Possible to set event.dataTransfer asynchronously after drag ...
Here is your answer. Firstly,You can only set data in your dragstart event. So, every time any dragstart event starts it sets value...
Read more >Cypress code-snippet#1- Drag and Drop feature
Approach 1: Using events such as dragstart, drop and dragend we can successfully achieve drag and drop. Create a new DataTransfer object, which...
Read more >7.7 Drag and drop — HTML5 - W3C
For the dragstart event. ... DataTransfer objects are used during the drag-and-drop events, ... Fire a DND event named dragstart at the source...
Read more >Drag-and-drop events in JavaScript - OpenReplay Blog
Drag : This event fires immediately after the dragstart and will fire continuously as we drag the element until we stop dragging it....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This would be a great feature to add to Cypress 👍
Here is a temporary workaround for the
dataTransfer
property. It’s value is DataTransfer which I am mocking in my tests. I don’t believe my current implementation covers all use cases of it:To get more info about
dataTransfer
, play around with it in your browser’s console: