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

prevent inner elements of renderItem to initiate drag and drop #95

Open
gsavvidis96 opened this issue Jun 29, 2023 · 0 comments
Open

prevent inner elements of renderItem to initiate drag and drop #95

gsavvidis96 opened this issue Jun 29, 2023 · 0 comments
Labels
question Further information is requested

Comments

@gsavvidis96
Copy link

Based on other issues I noticed that buttons are clickable, or elements with role="button". Although that is a partial fix, I have a use case where I dont want some inner elements of renderItem to initiate drag and drop. For example:

import { Stack, Typography } from "@mui/material";
import { useState } from "react";
import { List, arrayMove } from "react-movable";

const Test = () => {
  const [items, setItems] = useState([
    "item1",
    "item2",
    "item3",
    "item4",
    "item5",
  ]);

  return (
    <Stack sx={{ flexGrow: 1 }}>
      <List
        values={items}
        renderList={({ children, props }) => {
          return (
            <Stack {...props} gap={1}>
              {children}
            </Stack>
          );
        }}
        renderItem={({ value, props }) => {
          return (
            <Stack {...props} direction="row" gap={3}>
              <Typography>{value}</Typography>

              <Stack sx={{ backgroundColor: "grey.100" }} role="button">
                <Typography>
                  Content that does not trigger drag and drop !!
                </Typography>
              </Stack>
            </Stack>
          );
        }}
        onChange={({ oldIndex, newIndex }) =>
          setItems(arrayMove(items, oldIndex, newIndex))
        }
      />
    </Stack>
  );
};

export default Test;

By adding role="button" in the inner Stack I am able to prevent the drag and drop but still I am not able to highlight text. Is there any workaround for that or a more generic solution to preventing drag and drop for inner items?

Thanks

@tajo tajo added the question Further information is requested label Jul 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants