在 react-beautiful-dnd 中保留 Draggable Child 的同时从 Parent 移除 Draggable

Remove Draggable from Parent while Maintaining Draggable Child in react-beautiful-dnd

我有包含项目的列。目前,根据我从 react-beautiful-dnd 复制的代码,列和项目都是可拖动的,并且运行良好,但我不希望列是可拖动的。

如果我删除 <Draggable/> 组件,React 会因为使用子函数而感到不安。我尝试了很多其他的东西,但没有任何运气。关于如何从此组件中删除列拖动功能的任何建议?

// @flow
import React from 'react';
import PropTypes from 'prop-types';
import styled from 'react-emotion';
import { Draggable } from 'react-beautiful-dnd';
import { grid, colors, borderRadius } from './dnd/constants';
import PlayerList from './dnd/player-list';
import Title from './dnd/title';

const Container = styled('div')`
  margin: ${grid}px;
`;

const Header = styled('div')`
  display: flex;
  align-items: center;
  justify-content: center;
  border-top-left-radius: ${borderRadius}px;
  border-top-right-radius: ${borderRadius}px;
  background-color: ${({ isDragging }) => (isDragging ? colors.blue.lighter : colors.blue.light)};
  transition: background-color 0.1s ease;

  &:hover {
    background-color: ${colors.blue.lighter};
  }
`;

const Column = ({ title, players, index }) => (
  <Draggable draggableId={title} index={index}>
    {(provided, snapshot) => (
      <Container innerRef={provided.innerRef} {...provided.draggableProps}>
        <Header isDragging={snapshot.isDragging}>
          <Title
            isDragging={snapshot.isDragging}
            {...provided.dragHandleProps}
          >
            {title}
          </Title>
        </Header>
        <PlayerList
          listId={title}
          players={players}
        />
      </Container>
    )}
  </Draggable>
);

Column.propTypes = {
  title: PropTypes.string.isRequired,
  players: PropTypes.arrayOf(PropTypes.shape({})).isRequired,
  index: PropTypes.number.isRequired,
};

export default Column;
  1. 从您的 Column
  2. 中完全删除 Draggable
const Column = ({ title, players, index }) => (
 <Container>
   <Header isDragging={false}>
     <Title isDragging={false}>
        {title}
     </Title>
  </Header>
  <PlayerList
     listId={title}
     players={players}
   />
</Container>
);
  1. 您可能想要删除 Droppable 所有 Columns 的包装。这很可能位于您未在此处包含的 Board 组件中