Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.1k views
in Technique[技术] by (71.8m points)

antd中Tree组件的拖拽问题?

项目中使用到了Antd的Tree组件。节点拖拽效果里面,拖拽目标为<input/>时,也会产生整个结点的拖拽效果,导致文本框内内容无法被鼠标选中。此处如何让子元素的拖拽不触发父元素的拖拽效果呢?


具体现象如下:
image


关键部分相关代码如下:

<Tree
    showIcon
    draggable
    blockNode
    multiple={false}
    onDrop={this.onDrop.bind(this)}
    onSelect={this.handleMenuClick.bind(this)}
>
   {
      data.map((item,index) =>{
         return <TreeNode
            key={index}
            data-item={item}
            data-index={index}
            title={
                <div className="tree-content">
                    {
                        item.editable
                           ?
                        <Input
                            autoFocus
                            onBlur={this.reqChangeName.bind(this, item, index)}
                            onChange={this.changeGroupName.bind(this, item, index)}
                            onClick={(e) => {e.stopPropagation()}}
                            value={item.documentName} 
                        />
                           :
                        <div 
                            className="content-name" 
                            onDoubleClick={this.handleDblClick.bind(this, item, index)}
                        >
                            {item.documentName}
                        </div>
                    }
                </div>
         </TreeNode>
      })
   }
</Tree>

问题更新:
当文本框内内容超出文本框能显示的长度时,即可正常通过鼠标选中文本,有无方法利用此性质解决此处拖拽问题?文本框内容超出效果如下:
image


问题更新:
阻止文本框onMouseMove事件的默认行为,可以实现文本框内鼠标拖选事件不触发父元素的拖拽效果,但是文本框内容依旧无法被拖选中,效果如下:

<Input
    autoFocus
    onMouseMove={(e) => {e.preventDefault()}}
    onBlur={this.reqChangeName.bind(this, item, index)}
    onChange={this.changeGroupName.bind(this, item, index)}
    onClick={(e) => {e.stopPropagation()}}
    value={item.documentName} 
/>

image


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
<Input
  onDragStart={(event) => {
    event.stopPropagation();
    event.preventDefault();
  }}
></Input>

试试这个


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...