Fix sortable chip dragging style (#2150)

This commit is contained in:
Dawid 2022-07-13 13:11:38 +02:00 committed by GitHub
parent 51baacd0ff
commit b6312c2dff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,6 +1,6 @@
import { Typography } from "@material-ui/core"; import { Typography } from "@material-ui/core";
import { makeStyles } from "@saleor/macaw-ui"; import { makeStyles } from "@saleor/macaw-ui";
import { ReorderAction } from "@saleor/types"; import { ReorderAction, ReorderEvent } from "@saleor/types";
import React from "react"; import React from "react";
import { SortableContainerProps } from "react-sortable-hoc"; import { SortableContainerProps } from "react-sortable-hoc";
@ -15,6 +15,15 @@ const useStyles = makeStyles(
color: theme.palette.primary.dark, color: theme.palette.primary.dark,
marginBottom: theme.spacing(1), marginBottom: theme.spacing(1),
}, },
chipHelper: {
display: "flex",
justifyContent: "center",
alignItems: "center",
padding: 0,
},
grabbing: {
cursor: "grabbing",
},
errorText: { errorText: {
color: theme.palette.error.light, color: theme.palette.error.light,
}, },
@ -49,12 +58,23 @@ const SortableChipsField: React.FC<SortableChipsFieldProps> = props => {
} = props; } = props;
const classes = useStyles(props); const classes = useStyles(props);
const handleSortStart = () => {
document.body.classList.add(classes.grabbing);
};
const handleSortEnd = (event: ReorderEvent) => {
document.body.classList.remove(classes.grabbing);
onValueReorder(event);
};
return ( return (
<SortableContainer <SortableContainer
axis="xy" axis="xy"
lockAxis="xy" lockAxis="xy"
useDragHandle useDragHandle
onSortEnd={onValueReorder} onSortStart={handleSortStart}
onSortEnd={handleSortEnd}
helperClass={classes.chipHelper}
> >
<div> <div>
{loading ? ( {loading ? (