当我拖动一个元素时,react-sortable-hoc列表消失了。

3

JSFiddle: https://jsfiddle.net/40vpaLj5/

我在谷歌上搜索了一些相关问题,唯一与消失有关的问题是当人们在模态框上使用时,并且他们提到设置z-index来解决问题。 我尝试了这个方法,但依然没用。 有什么办法可以解决这个问题?

import React from 'react';
import PlaylistPages from './PlaylistPages';

class PlaylistSortableComponent extends React.Component {
  constructor(props, context) {
    super(props, context);

    this.state = {
      test: [
        '1','2', '3', '4'
      ]
    }
  }

  render() {
    return (
      <PlaylistPages pages={this.state.test} style={{zIndex: 999999}} />
    );
  }
}   


const PlaylistPages = SortableContainer(({pages}) => {
  return (
    <div>
      {
        pages.map((page, index) =>
          <PlaylistPage key={index} page={page} style={{zIndex: 99999999}} />
      )}
    </div>
  );
});   

const PlaylistPage = SortableElement(({page}) => {
  return (
    <div style={{zIndex: 99999999}} >{page}</div>
  );
});
2个回答

10

每个 sortableElement 都应该有自己的 index 属性:

<PlaylistPage key={index} index={index} page={page} style={{zIndex: 99999999}} />

这是您的 jsfiddle 更新内容:
https://jsfiddle.net/40vpaLj5/1/


2
我非常爱你。我已经苦思冥想了好几个小时了。 - user1189352
我错过的这个简单的东西也让我抓狂了。谢谢! - gion_13

2

我遇到了相同的问题,Dekel是正确的。在我的情况下,z-index修复了错误:

<SortableList
    axis="y"
    helperClass="sortable-list-tab"
    lockAxis="y"
    distance={0}
    onSortEnd={onSortEnd}
>
    <ul>
       {toolItems.map((value, index) => (
          <SortableItem key={`item-${index}`} index={index}>
              <li className="sortable-list-tab" >
                 <Button type="dashed">{`${value.label} (${index + 1})`}</Button>
              </li>
          </SortableItem>
        ))}
    </ul>
</SortableList>

而sortable-list-tab类看起来像:

.sortable-list-tab {
    cursor: default;
    visibility: visible;
    z-index: 99999999;
    list-style-type: none;
    padding: .3em;
  }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接