From 57b81c286a40558896b6905767465988136825a4 Mon Sep 17 00:00:00 2001 From: 2betop <2betop.cn@gmail.com> Date: Thu, 13 Aug 2020 14:46:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20Tree=20onlyChild=20?= =?UTF-8?q?=E7=94=A8=E6=B3=95=E7=9A=84=E4=B8=80=E4=B8=AA=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Tree.tsx | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/components/Tree.tsx b/src/components/Tree.tsx index eb429b66..2e4c1090 100644 --- a/src/components/Tree.tsx +++ b/src/components/Tree.tsx @@ -57,6 +57,9 @@ interface TreeSelectorProps extends ThemeProps, LocaleProps { hideRoot?: boolean; rootLabel?: string; rootValue?: any; + + // 这个配置名字没取好,目前的含义是,如果这个配置成true,点父级的时候,孩子几点不会自选中。 + // 否则点击父级,孩子节点选中。 cascade?: boolean; selfDisabledAffectChildren?: boolean; minLength?: number; @@ -247,16 +250,18 @@ export class TreeSelector extends React.Component< if (onlyChildren) { // 父级选中的时候,子节点也都选中,但是自己不选中 - !~idx && children.length && value.shift(); + !~idx && children.length && value.pop(); while (children.length) { let child = children.shift(); let index = value.indexOf(child); + if (!~index && child.value !== 'undefined') { + value.push(child); + } + if (child.children) { children.push.apply(children, child.children); - } else { - ~index || value.push(child); } } } else { @@ -279,7 +284,7 @@ export class TreeSelector extends React.Component< } } } - } else if (!checked) { + } else { ~idx && value.splice(idx, 1); if (!props.cascade && (props.withChildren || onlyChildren)) { @@ -535,7 +540,7 @@ export class TreeSelector extends React.Component< size="sm" disabled={nodeDisabled} checked={checked} - onChange={this.handleCheck.bind(this, item)} + onChange={this.handleCheck.bind(this, item, !selfChecked)} /> ) : showRadio ? (