react-draggable icon indicating copy to clipboard operation
react-draggable copied to clipboard

TypeError: Cannot read property 'className' of undefined

Open fabio-felizzi opened this issue 4 years ago • 3 comments
trafficstars

React version - 17.0.2 Draggable version - 4.4.4

<Draggable
        axis="x"
        handle=".handle"
        defaultPosition={{ x: 0, y: 0 }}
        bounds={{ left: '-100vw', right: 0 }}
        position={0}
        onDrag={handleDrag}
      >
        <div>
          <section>
            {children}
          </section>
          <button className="handle">test</button>
        </div>

in the above snippet I am getting the console error noted in the title. I have tried with the handle prop as well as nodeRef but either way I got the same error.

the error is at the top of my call stack here

Draggable.render
file:///Users/{user}/Documents/Repos/ssr-prototype/node_modules/react-draggable/build/cjs/Draggable.js (288:58)

I've used draggable in an old react 16 project and it worked perfectly. is there something I'm missing?

fabio-felizzi avatar Nov 02 '21 17:11 fabio-felizzi

Facing the same problem. Any update on this issue?

hasheemismath avatar Nov 08 '21 15:11 hasheemismath

Same problem here, I checked the source code. The following method will solve the issue

<Draggable
        axis="x"
        handle=".handle"
        defaultPosition={{ x: 0, y: 0 }}
        bounds={{ left: '-100vw', right: 0 }}
        position={0}
        onDrag={handleDrag}
        children={(<div>
          <section>
            {children}
          </section>
          <button className="handle">test</button>
        </div>)}
      >        

it seems that you should use the children attributes. Not sure why should do like this

hymRedemption avatar Nov 19 '21 09:11 hymRedemption

Try this: <Draggable><div>all your content</div></Draggable>. This worked for me!

vesaademi avatar Dec 02 '21 15:12 vesaademi