Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong draggable position when using example code #2056

Open
rendomnet opened this issue Jan 10, 2021 · 9 comments
Open

Wrong draggable position when using example code #2056

rendomnet opened this issue Jan 10, 2021 · 9 comments

Comments

@rendomnet
Copy link

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.

Screen.Recording.2021-01-10.at.11.34.53.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
Copy link
Author

rendomnet commented Jan 10, 2021

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.

@victorhsr
Copy link

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
Copy link

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

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

@barisgunduz
Copy link

barisgunduz commented Dec 2, 2022

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.

@bluewolfali
Copy link

bluewolfali commented Jul 10, 2023

@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>

@Alireza-Mohammadhossein

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!

@zreecespieces
Copy link

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.

@jsonchou
Copy link

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.

@Justin99b
Copy link

Justin99b commented Aug 29, 2024

Okay thank you guys i had a background blur applied to a parent and i never would have found this out. This is so random haha

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants