选中的节点第二次点击时还是选中,不自动取消选中

This commit is contained in:
wanghaoo 2018-12-04 10:24:05 +08:00
parent 439ca5981c
commit acd7be199d
6 changed files with 46 additions and 19 deletions

View File

@ -51,6 +51,7 @@ class Demo1 extends Component {
defaultCheckedKeys = {this.state.defaultCheckedKeys}
checkStrictly
showIcon
cancelUnSelect={true}
onSelect={this.onSelect} onCheck={this.onCheck}
onDoubleClick={this.onDoubleClick}
>

File diff suppressed because one or more lines are too long

31
dist/demo.js vendored

File diff suppressed because one or more lines are too long

2
dist/demo.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -18,6 +18,7 @@
|checkStrictly|精细的检查每个节点|bool|false
|defaultSelectedKeys|指定选中的节点key|String[]|[]
|selectedKeys|指定选中的节点keys(controlled)|String[]|-
|cancelUnSelect|选中的节点第二次点击时还是选中,不自动取消选中|bool|false
|showLine|是否显示连接线|bool|false
|openIcon|自定义展开节点图标的名称[参考这里](http://bee.tinper.org/bee-icon)String[]|-
|closeIcon|自定义关闭节点图标的名称[参考这里](http://bee.tinper.org/bee-icon)String[]|-

View File

@ -279,16 +279,28 @@ class Tree extends React.Component {
const eventKey = treeNode.props.eventKey;
const index = selectedKeys.indexOf(eventKey);
let selected;
if (index !== -1) {
selected = false;
selectedKeys.splice(index, 1);
} else {
selected = true;
if (!props.multiple) {
selectedKeys.length = 0;
//cancelUnSelect为true时第二次点击时不取消选中
if(props.cancelUnSelect){
if (index == -1) {
selected = true;
if (!props.multiple) {
selectedKeys.length = 0;
}
selectedKeys.push(eventKey);
}
}else{
if (index !== -1) {
selected = false;
selectedKeys.splice(index, 1);
} else {
selected = true;
if (!props.multiple) {
selectedKeys.length = 0;
}
selectedKeys.push(eventKey);
}
selectedKeys.push(eventKey);
}
const selectedNodes = [];
if (selectedKeys.length) {
loopAllChildren(this.props.children, (item) => {