Strange "Ghost" Silhouette of Draggable Element When Using Non-integer (i.e., numbers with decimals)

Open
#744 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
javascript, react
Domain
frontend

Research direction

Start with the Draggable component's controlled position handling and reproduce the provided example using decimal x and y values. Trace the drag-start behavior after handleDragStop sets the position, then verify that dragging no longer shows a silhouette when the position contains decimals.

Written by the indexing model from the issue text.

Description

If you set the state of a Draggable element's position to a non-integer (i.e., a number with decimals, like 123.4), you will get a strange silhouette of the element when dragging it. Consider this example:

import { useState } from 'react';

interface PositionModel {
  x: number;
  y: number;
}

const MyComponent = () => {
  const [pos, setPos] = useState({ x: 0, y: 0 } as PositionModel);
  const handleDragStop = (_e: DraggableEvent, position: DraggableData) => {
    setPos({ x: 456.2, y: 229.8 });
  };

  return (
    <Draggable
      position={pos}
      onStop={handleDragStop}
    >
      <div>I am an element</div>
    </Draggable>
  );
};

After the handleDragStop function is triggered and you go to drag the component again, you'll see something similar to this:

2024-03-21_15-35-18

Dominant language
JavaScript
Stars
9.3k
Forks
1k
Avg merge
3d 8h
Merged PRs (30d)
4

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from react-grid-layout/react-draggable

All issues in react-grid-layout/react-draggable

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.