拖动时,react-beautiful-dnd在material-ui-next.com持久抽屉中未显示可拖动项 [英] On drag, react-beautiful-dnd doesn't show draggable item in material-ui-next.com persistent drawer

查看:172
本文介绍了拖动时,react-beautiful-dnd在material-ui-next.com持久抽屉中未显示可拖动项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个永久抽屉,其中包含一个带有可拖动项目的可放置列表.有功能,但是在拖动项目时,不会显示正在拖动的项目.我可以完美地拖动项目,并且正在分配空间,包括dnd框架想要的动画,我只是看不到我在拖动什么.如果我将抽屉更改为永久抽屉,则一切正常.有什么建议吗?

I have a persistent drawer which holds a droppable list with draggable items. The functionality is there, but when dragging an item the item that is being dragged is not shown. I can drag the item perfectly and space is being allocated including animations as intended by the dnd framework, I just can't see what I am dragging. If I change the drawer to a permanent drawer, everything works as expected. Any suggestions?

我的组件(在原型代码中): (DragDropContext在父组件中声明)

My component (in prototype code): (The DragDropContext is declared in a parent component)

import React from 'react';
import { Divider, Drawer, IconButton, List, ListItem, Paper, 
withStyles } from 'material-ui';
import { Draggable, Droppable } from 'react-beautiful-dnd';

const styles = {
  list: {
    width: 250,
    marginTop: 70
  },
};

const getItemStyle = (isDragging, draggableStyle) => ({
  // some basic styles to make the items look a bit nicer
  userSelect: 'none',
  padding: 8 * 2,
  margin: `0 0 8px 0`,

  // change background colour if dragging
  background: isDragging ? 'lightgreen' : 'red',

  // styles we need to apply on draggables
      ...draggableStyle,

});

const getListStyle = isDraggingOver => ({
  background: isDraggingOver ? 'lightblue' : 'none',
  padding: 8,
  width: 250,
});

class WidgetDrawer extends React.Component {

  state = { items: [{ id: 1, content: 'Widget A'}, { id: 2, content: 'Widget B'}]};

  renderWidgets() {
    const widgets = [{
      name: 'Widget A'
    }, {
      name: 'Widget B'
    }];

    return widgets.map((widget, index) => {
      return <Draggable key={widget.name} draggableId={widget.name} index={index}>
                  {(provided, snapshot) => (
                    <div>
                      <div
                        ref={provided.innerRef}
                        {...provided.draggableProps}
                        {...provided.dragHandleProps}
                        style={getItemStyle(
                          snapshot.isDragging,
                          provided.draggableProps.style
                        )}
                      >
                        <ListItem>
                          <Paper>
                            {widget.name}
                          </Paper>
                        </ListItem>
                      </div>
                      {provided.placeholder}
                    </div>
                  )}
                </Draggable>
    })
  }

  render() {

    const { classes } = this.props;

    const fullList = (
      <div className={classes.list}>
          <Droppable droppableId="droppable">
          {(provided, snapshot) => (
            <div
              ref={provided.innerRef}
              style={getListStyle(snapshot.isDraggingOver)}
            >
              {this.state.items.map((item, index) => (
                <Draggable key={item.id} draggableId={item.id} index {index}>
                  {(provided, snapshot) => (
                    <div>
                      <div
                        ref={provided.innerRef}
                        {...provided.draggableProps}
                        {...provided.dragHandleProps}
                        style={getItemStyle(
                          snapshot.isDragging,
                          provided.draggableProps.style
                        )}
                      >
                        {item.content}
                      </div>
                      {provided.placeholder}
                    </div>
                  )}
                </Draggable>
              ))}
              {provided.placeholder}
            </div>
          )}
        </Droppable>
      </div>
    );

    return (
     <Drawer
       variant='permanent'
       anchor="right"
       open={this.props.open}
       onClose={this.props.toggleDrawer}>
      <div
        tabIndex={0}
        role="button"
        onClick={this.props.toggleDrawer}
        onKeyDown={this.props.toggleDrawer}
      >
        {fullList}
      </div>
    </Drawer>
    )
  }
}

export default withStyles(styles)(WidgetDrawer);

推荐答案

可以通过覆盖

const getItemStyle = (isDragging, draggableStyle) => ({
  ...draggableStyle,
  userSelect: 'none',
  position:static,
  padding: 8 * 2,
  margin: `0 0 8px 0`,
  background: isDragging ? 'lightgreen' : 'red',    
});

这篇关于拖动时,react-beautiful-dnd在material-ui-next.com持久抽屉中未显示可拖动项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆