Skip to content

Commit

Permalink
Fixed an issue with dragging items when two have the same name
Browse files Browse the repository at this point in the history
  • Loading branch information
ericsoderberghp committed Oct 21, 2020
1 parent 050cc7d commit ec90784
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/Roadmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ const Roadmap = ({ identifier, onClose }) => {
const moveItem = useCallback(
(event) => {
const nextRoadmap = JSON.parse(JSON.stringify(roadmap));
const nextItem = nextRoadmap.items.find(({ name }) => name === dragging);
const nextItem = nextRoadmap.items.find((_, index) => index === dragging);
nextItem.target = dropTarget.toISOString();
event.dataTransfer.clearData();
setRoadmap(nextRoadmap);
Expand Down Expand Up @@ -284,21 +284,21 @@ const Roadmap = ({ identifier, onClose }) => {
gap="medium"
pad={{ vertical: 'medium', horizontal: 'small' }}
background={
dragging && dropTarget !== month
dragging !== undefined && dropTarget !== month
? 'background-contrast'
: 'background-back'
}
responsive={false}
onDragEnter={(event) => {
if (dragging) {
if (dragging !== undefined) {
event.preventDefault();
setDropTarget(month);
} else {
setDropTarget(undefined);
}
}}
onDragOver={(event) => {
if (dragging) event.preventDefault();
if (dragging !== undefined) event.preventDefault();
}}
onDrop={moveItem}
>
Expand All @@ -317,7 +317,7 @@ const Roadmap = ({ identifier, onClose }) => {
onDragStart={(event) => {
// for Firefox
event.dataTransfer.setData('text/plain', '');
setDragging(name);
setDragging(index);
}}
onDragEnd={() => {
setDragging(undefined);
Expand Down

0 comments on commit ec90784

Please sign in to comment.