保持可拖动子项处于react-beautiful-dnd

时间:2019-04-25 15:45:25

标签: reactjs 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 个答案:

答案 0 :(得分:1)

  1. 从您的// good cards const ammoCards = [...Array(4)].map(i => new Card('ammunition', null, 1, null)); const beerCards = [...Array(4)].map(i => new Card('beer', null, 1, null)); // all other good cards ... const goodCards = [...ammoCards, ...beerCards]; // repeat for bad cards // and then const allCards = [...goodCards, ...badCards]; 完全删除Draggable
Column
  1. 您可能要删除所有const Column = ({ title, players, index }) => ( <Container> <Header isDragging={false}> <Title isDragging={false}> {title} </Title> </Header> <PlayerList listId={title} players={players} /> </Container> ); 的{​​{1}}包装。这很可能在Droppable组件中,您没有在其中包含
相关问题