Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tree组件 editable 受控状态下,编辑菜单显示出现问题 #1761

Closed
zhan8863 opened this issue Jun 2, 2021 · 0 comments · Fixed by #1765
Closed

Tree组件 editable 受控状态下,编辑菜单显示出现问题 #1761

zhan8863 opened this issue Jun 2, 2021 · 0 comments · Fixed by #1765
Labels
bug Something isn't working comp:tree

Comments

@zhan8863
Copy link
Collaborator

zhan8863 commented Jun 2, 2021

正常情况下:editable=true,contextmenu 正常显示隐藏
异常情况: 当editable为一个受控值时,将editable由true置为false再成为true,此时contextmenu无法显示;
以下为代码:

`import React from 'react'
import Tree from '@hi-ui/hiui/es/tree'

class Demo extends React.Component {
  constructor(props) {
    super(props)
    this.state = {
      a: true,
      treeData: [
        { id: 1, title: '小米快递',
          children: [
            { id: 3, title: '后端', onClick: data => {console.log('后端:', data)} },
            { id: 4, title: '运维' , disabled: true},
            { id: 5, title: '前端' },
            { id: 6, title: '点击右键', customData: 'Y' }
          ]
        }
      ]
    }

  }
  render() {
    return (
      <div style={{width:500}}>
        <button onClick={() => this.setState({a: !this.state.a})}>click</button>
        <Tree
          searchable
          defaultExpandAll
          editable={this.state.a}
          data={this.state.treeData}
          onSave={(saveNode, data, level) => {
            if (level === 0) {
              Notification.open({
                title:'保存失败',
                type:'error'
              })
              return false
            } else {
              return true
            }
            console.log(saveNode, data,level)

          }}

          onDelete={(deleteNode, data) => {
            console.log(deleteNode, data)
          }}
          contextMenu={(currentItemData, level) => {
            if (currentItemData.customData === 'Y') {
              return [{
                type: 'addChildNode'
              }]
            }
            return  [{
              type: 'editNode'
            }, {
              title: '自定义 Title-1',
              onClick: (item) => {
                alert(JSON.stringify(item))
              }
            }, {
              type: 'editNode',
              title: '自定义 Title-2'
            }, {
              title: '自定义 Title-3',
              type: 'editNode',
              onClick: (item, node) => {
                console.log('执行内置事件')
                node.editNode(item)
              }
            }, {
              title: '自定义 Title-4',
              onClick: (item, node) => {
                console.log('自定义编辑节点事件')
              }
            }]
          }}
          onChange={data => {console.log('Tree data:', data)}}
        />
      </div>
    )
  }

}`

@zhan8863 zhan8863 added the bug Something isn't working label Jun 2, 2021
@GleanCoder1116 GleanCoder1116 linked a pull request Jun 6, 2021 that will close this issue
GleanCoder1116 pushed a commit that referenced this issue Jun 6, 2021
Flcwl added a commit that referenced this issue Jun 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working comp:tree
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants