-
Notifications
You must be signed in to change notification settings - Fork 2
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
base: beta-master
Are you sure you want to change the base?
Dnd zone enhancement #692
Conversation
<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}> |
There was a problem hiding this comment.
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.
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: