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

Dnd zone enhancement #692

Open
wants to merge 2 commits into
base: beta-master
Choose a base branch
from
Open

Dnd zone enhancement #692

wants to merge 2 commits into from

Conversation

Sallaa
Copy link
Contributor

@Sallaa Sallaa commented Dec 13, 2024

Building from your recent changes @ianroberts, I am adding a bigger drag and drop zone with a clear zone for where the file is droppable into. I am adding you as a reviewer Ian if you want to have a look.

I also moved the code from onDragEnter to onDragMove because it sometimes made my browser open the file in a new tab. It seems fixed now.

The upload zone looks like this:

Screenshot 2024-12-13 at 11 06 42

@Sallaa Sallaa changed the base branch from master to beta-master December 13, 2024 10:08
@Sallaa Sallaa requested a review from ianroberts December 13, 2024 10:09
@Sallaa Sallaa marked this pull request as ready for review December 13, 2024 10:10
Comment on lines +110 to +126
<Box
onDragOver={onDragOver}
onDragLeave={onDragLeave}
onDrop={onDrop}
sx={{
border: isDragging ? "4px dashed #00926c" : "0",
height: isDragging ? fieldsDivHeight : "auto",
backgroundColor: isDragging ? dropColor : "initial",
}}
>
{isDragging && (
<Stack justifyContent="center" alignItems="center" height="100%">
<Typography>{keyword("droppable_zone")}</Typography>
</Stack>
)}

<Box visibility={isDragging ? "hidden" : "visible"} ref={fieldsRef}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can probably get away without the useRef and the effect if you do something like

    <Box
      onDragOver={onDragOver}
      onDragLeave={onDragLeave}
      onDrop={onDrop}
      sx={{
        position: "relative",
      }}
    >
      <Box>
        {/* form content goes here */}
      </Box>

      {isDragging && (
        <Stack
          sx={{
            border: "4px dashed #00926c",
            backgroundColor: dropColor,
            justifyContent: "center",
            alignItems: "center",
            position: "absolute",
            top: 0,
            left: 0,
            bottom: 0,
            right: 0,
          }}
        >
          <Typography>{keyword("droppable_zone")}</Typography>
        </Stack>
      )}
    </Box>

This uses absolute positioning to put the drop zone box on top of the form fields area, and it doesn't need the effect to track the height as it gets that automatically with t/l/b/r all set to zero. To get this to work I've had to move the Stack after the Box, if you leave them the other way round you might need a zIndex on the Stack to make it sit on top.

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

Successfully merging this pull request may close these issues.

2 participants