react-beautiful-dnd icon indicating copy to clipboard operation
react-beautiful-dnd copied to clipboard

Wrong draggable position when using example code

Open rendomnet opened this issue 3 years ago • 8 comments

I'm testing react-beautiful-dnd in my electron app. You can see draggable item is moved to the right for approx 50px. And when it is dropped it is also teleported 50px to the left.

https://user-images.githubusercontent.com/18900210/104115286-f134ad00-5337-11eb-95cd-9725513c0c27.mov

const getItemStyle = (isDragging, draggableStyle) => ({
  // some basic styles to make the items look a bit nicer
  userSelect: 'none',
  padding: grid * 2,
  width: '200px',
  height: '200px',
  margin: `0 ${grid}px 0 0`,

  // change background colour if dragging
  background: isDragging ? 'lightgreen' : 'grey',

  // styles we need to apply on draggables
  ...draggableStyle,
});

const getListStyle = (isDraggingOver) => ({
  background: isDraggingOver ? 'lightblue' : 'lightgrey',
  display: 'flex',
  padding: grid,
  overflow: 'auto',
});
...


      <DragDropContext onDragEnd={onDragEnd}>
        <Droppable droppableId="droppable" direction="horizontal">
          {(provided, snapshot) => (
            <div
              ref={provided.innerRef}
              style={getListStyle(snapshot.isDraggingOver)}
              {...provided.droppableProps}
            >
              {list.map((item, index) => (
                <Draggable key={item.id} draggableId={item.id} index={index}>
                  {(provided, snapshot) => (
                    <div
                      ref={provided.innerRef}
                      {...provided.draggableProps}
                      {...provided.dragHandleProps}
                      style={getItemStyle(
                        snapshot.isDragging,
                        provided.draggableProps.style
                      )}
                    >
                    </div>
                  )}
                </Draggable>
              ))}
              {provided.placeholder}
            </div>
          )}
        </Droppable>
      </DragDropContext>

rendomnet avatar Jan 10 '21 05:01 rendomnet

Okay I have found the reason but it is strange one. I have a container div around DragDropContext with style backdrop-filtter. And if I remove this style backdrop-filtter from container div. Bug disappears.

rendomnet avatar Jan 10 '21 06:01 rendomnet

Any update about this issue? I'm facing the same problem, when i remove the backdrop-filter from my container div, the bug disappears 🤔

victorhsr avatar Aug 11 '22 17:08 victorhsr

Ok I've just solved my problem by overriding the left/top definitions of my Draggable to auto:

left: auto !important; top: auto !important;

victorhsr avatar Aug 11 '22 17:08 victorhsr

left: auto !important; top: auto !important;

If your Droppable column is vertical and there exists scroll, this doesnt work when you scroll down. Cant find how to fix it.

barisgunduz avatar Dec 02 '22 07:12 barisgunduz

@barisgunduz left: auto !important; top: auto !important;

If your Droppable column is vertical and there exists scroll, this doesnt work when you scroll down. Cant find how to fix it.

If your Droppable column is vertical and there exists scroll, You can try the following code

<Draggable
  key={rowInfo.original.id}
  draggableId={rowInfo.original.id}
  index={rowInfo.index}
>
  {(provided, snapshot): React.ReactElement<HTMLElement> => {
    if (
      provided.draggableProps.style &&
      "top" in provided.draggableProps.style &&
      "left" in provided.draggableProps.style
    ) {
      provided.draggableProps.style.left -= 50;
      provided.draggableProps.style.top -= 50;
    }
    return (
      <div
        ref={provided.innerRef}
        {...provided.draggableProps}
        {...provided.dragHandleProps}
      >
        <ReactTableDefaults.TrComponent
          onClick={handleRowClick}
          className={clsx(
            "w-full",
            snapshot.isDragging ? classes.dragTableRow : ""
          )}
        >
          {children}
        </ReactTableDefaults.TrComponent>
      </div>
    );
  }}
</Draggable>

bluewolfali avatar Jul 10 '23 17:07 bluewolfali

Okay I have found the reason but it is strange one. I have a container div around DragDropContext with style backdrop-filtter. And if I remove this style backdrop-filtter from container div. Bug disappears.

It is totally weird, I have this problem, and when I remove the backdrop for its parent problem solved!

Alireza-Mohammadhossein avatar Oct 18 '23 09:10 Alireza-Mohammadhossein

Ok I've just solved my problem by overriding the left/top definitions of my Draggable to auto:

left: auto !important; top: auto !important;

oh my god thank you so much. this totally worked.

zreecespieces avatar Jan 22 '24 15:01 zreecespieces

Okay I have found the reason but it is strange one. I have a container div around DragDropContext with style backdrop-filtter. And if I remove this style backdrop-filtter from container div. Bug disappears.

Yeah, I'm totally shocked by this bug. Remove the style of backdrop-filter make it work.

jsonchou avatar Apr 24 '24 01:04 jsonchou