Open electroluxcode opened 1 month ago
Hi @electroluxcode, thanks for taking the time to open this.
fireEvent
is a very low level API, all it does is dispatch the event based on the configuration.
I think you should be trying your use case with user-event
instead.
To top that, I'm not sure I understand the reasoning behind calling e.preventDefault()
in onDragStart
(afaik, usually calling e.preventDefault
in drag scenarios only has meaning in onDragOver
or onDragEnter
to mark that an item can be dropped somewhere).
I'm also not sure the browser's behavior is following the spec and I couldn't find any mention about that. Are you familiar with any spec that defines this behavior?
Hi @electroluxcode, thanks for taking the time to open this.
fireEvent
is a very low level API, all it does is dispatch the event based on the configuration. I think you should be trying your use case withuser-event
instead. To top that, I'm not sure I understand the reasoning behind callinge.preventDefault()
inonDragStart
(afaik, usually callinge.preventDefault
in drag scenarios only has meaning inonDragOver
oronDragEnter
to mark that an item can be dropped somewhere). I'm also not sure the browser's behavior is following the spec and I couldn't find any mention about that. Are you familiar with any spec that defines this behavior?
@MatanBobi Thank you very much for your reply. The reason I call e.preventDefault()
in onDragStart
is to avoid dragging some page elements that shouldn't be draggable. You can refer to
This is a snippet of react-dnd code where this logic is encapsulated within the onDragStart
method.
I wanted to write test cases for this code snippet, but found that the onDragStart
event behaves unexpectedly during testing.
and after reading your reply, I looked into user-event, but it seems there are no methods related to dragStart
or dragOver
.
and regarding the browser's behavior you mentioned, you can refer to https://html.spec.whatwg.org/multipage/dnd.html#dndevents.
Reproduction:
What you did:
run it in brower and testing env
Problem description:
when I run this component in the browser,
onDragOver
isn't executed due toe.preventDefault()
in theonDragStart
test case,but
onDragOver
is executed in testing env afteronDragStart
Expect
ii should prevent
onDragOver
fn in test env