kutlugsahin / smooth-dnd

drag and drop library for javascript
MIT License
599 stars 147 forks source link

Cannot read property 'getOptions' of undefined #43

Closed johannes-z closed 5 years ago

johannes-z commented 5 years ago

I get the following error when hiding/unhiding the container where the drag-handle is in and clicking the drag-handle:

I narrowed down the error, which happens when the Container receives classes that change, e.g. when adding/removing a class conditionally. As soon as the classList changes, the error gets thrown.

index.js?c878:formatted:785 Uncaught TypeError: Cannot read property 'getOptions' of undefined
    at HTMLDocument.De (index.js?c878:formatted:785)

I think it is this function:

https://github.com/kutlugsahin/smooth-dnd/blob/136e6d50251aeae4cfb466a55ef6d16224d01516/src/mediator.ts#L321

I have a private repo that serves as a repro, I added you, @kutlugsahin, as a contributor to check the error.

kutlugsahin commented 5 years ago

Hey @johannes-z ,

I just made a quick look. Your Container has some components other than Draggable. Try to organize your structure so that Container will have only Draggable type of children. Otherwise anything can go wrong. Let me know if the issue insists after doing that.

Cheers!

johannes-z commented 5 years ago

@kutlugsahin Thanks, that did actually work. For everybody else having the same issue (I'm using vue):

This does not work:

<Container>
  <h2>Some Heading</h2>
  <Draggable>...</Draggable>
</Container>

This works:

<h2>Some Heading</h2>
<Container>
  <Draggable>...</Draggable>
</Container>