question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

layoutItem is undefined `onDrop`

See original GitHub issue

I have an onDrop function, which is nearly identical to the example:

function onDrop(layout, layoutItem, _event) {
	console.log(layout, layoutItem, _event)
	alert(`Dropped element props:\n${JSON.stringify(layoutItem, ['x', 'y', 'w', 'h'], 2)}`)
}

I have my draggable element:

<div className="toolbox-draggable-button"
	draggable={true}
	unselectable="on"
	// this is a hack for firefox
	// Firefox requires some kind of initialization
	// which we can do by adding this attribute
	// @see https://bugzilla.mozilla.org/show_bug.cgi?id=568313
	onDragStart={e => e.dataTransfer.setData('text/plain', '')}>
		Text here
</div>

Whenever onDrop is called, layoutItem is undefined, and I’d like to integrate this into my app so that when a user drags the element onto it, it actually makes an element drop in, but I can’t even get to that point if layoutItem returns undefined.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8

github_iconTop GitHub Comments

3reactions
nickjpanellacommented, May 9, 2022

This seems to be the culprit - line below has a layout and a find function, but when it comes to ResponsiveGrid, layout is not an array, its an object with defined breakpoints. https://github.com/react-grid-layout/react-grid-layout/blob/5126e7be9a1e38053e078f2b17e1a0f3a7abcda0/lib/ReactGridLayout.jsx#L753

0reactions
joegrenancommented, Mar 16, 2022

@joegrenan did you manage to solve this? I’m having the same problem.

Edit: Strangely enough, when I remove the onLayoutChange callback, the layoutItem is set correctly in the onDrop callback.

Interesting, so in order for the onDrop to work, I have to give up on saving the layout to LocalStorage, or otherwise. Good find!

I wish I could say I’d figured it out, but alas, not yet. Let me know if you find a fix.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Item is dropped in wrong position using react-grid-layout on ...
I figured out. I added data-grid={el} to the element which should be dropped. This is the code. import React from "react"; import _...
Read more >
react-grid-layout/ReactGridLayout.jsx at master - GitHub
A draggable and resizable grid layout with responsive breakpoints, for React. - react-grid-layout/ReactGridLayout.jsx at master ...
Read more >
ehome-react-grid-layout - npm
onDrop : (layout: Layout, item: ?LayoutItem, e: Event) => void, // Calls when an element is being dragged over the grid from outside...
Read more >
LayoutItem Members | WPF Controls
Represents a control that consists of a label and content regions. The LayoutItem cannot be used outside a LayoutControl. #Constructors. Name, Description ...
Read more >
react-grid-layout | Yarn - Package Manager
'start' and 'stop' callbacks pass `undefined` for 'placeholder'. // type ItemCallback = (layout: ... onDrop: (layout: Layout, item: ?LayoutItem, e: Event) ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found