Skip to content

Commit a288575

Browse files
authoredMar 16, 2022
fix(Transfer): 选项为多层tree时可添加总数统计错误 (#669)
1 parent f89d852 commit a288575

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed
 

‎packages/react-transfer/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
Transfer 双栏穿梭选择框控件
22
===
33

4+
[![Open in unpkg](https://img.shields.io/badge/Open%20in-unpkg-blue)](https://uiwjs.github.io/npm-unpkg/#/pkg/@uiw/react-transfer/file/README.md)
5+
[![NPM Downloads](https://img.shields.io/npm/dm/@uiw/react-transfer.svg?style=flat)](https://www.npmjs.com/package/@uiw/react-transfer)
6+
[![npm version](https://img.shields.io/npm/v/@uiw/react-transfer.svg?label=@uiw/react-transfer)](https://npmjs.com/@uiw/react-transfer)
7+
48
选择一个或以上的选项后,点击左右的方向按钮,可以把选中的选项移动到另一栏为选中。在 v4.14.0+ 添加。
59

610
## 基础用法

‎packages/react-transfer/src/index.tsx

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect, useState } from 'react';
1+
import React, { useEffect, useRef, useState } from 'react';
22
import { IProps } from '@uiw/utils';
33
import Card from '@uiw/react-card';
44
import Icon from '@uiw/react-icon';
@@ -41,6 +41,7 @@ function Transfer(props: TransferProps) {
4141
const [searchValueLeft, searchValueLeftSet] = useState('');
4242
const [searchValueRight, searchValueRightSet] = useState('');
4343
const [selectedOptions, selectedOptionSet] = useState<Array<TreeData>>(options || []);
44+
const selectedOptionsShowCount = useRef<number>(0);
4445
const [selectOption, selectOptionSet] = useState<Map<string | number, string>>(new Map());
4546
const [leftSelectedKeys, leftSelectedKeySet] = useState<Array<string | number | undefined>>([]);
4647
const [rightSelectedKeys, rightSelectedKeySet] = useState<Array<string | number | undefined>>([]);
@@ -56,6 +57,7 @@ function Transfer(props: TransferProps) {
5657
}, [JSON.stringify(value)]);
5758

5859
const hiddenNode = (callBackfn: (child: TreeData) => boolean) => {
60+
selectedOptionsShowCount.current = 0;
5961
const hiddenNodeForSeach = (childrens: TreeData[]) => {
6062
childrens.forEach((child: TreeData) => {
6163
const isHide = callBackfn(child); // && parentIsHide;
@@ -65,6 +67,9 @@ function Transfer(props: TransferProps) {
6567
child.hideNode = isHide && !find;
6668
} else {
6769
child.hideNode = isHide;
70+
if (!child.hideNode) {
71+
selectedOptionsShowCount.current++;
72+
}
6873
}
6974
});
7075
};
@@ -83,12 +88,7 @@ function Transfer(props: TransferProps) {
8388
selectOptionSet(selectOptionTemp);
8489
};
8590

86-
const rightTreeOnSelected = (
87-
selectedKeys: Array<string | number | undefined>,
88-
_1: any,
89-
_2: boolean,
90-
evn: TreeData,
91-
) => {
91+
const rightTreeOnSelected = (selectedKeys: Array<string | number | undefined>) => {
9292
rightSelectedKeySet(selectedKeys);
9393
selectedKeys.forEach((key) => {
9494
selectOption.delete(key!);
@@ -105,7 +105,6 @@ function Transfer(props: TransferProps) {
105105
}
106106
};
107107
const iteratorParent = (child: TreeData) => {
108-
// 向上迭代
109108
if (child.parent) {
110109
const selectCount = child.parent.children.filter((child: TreeData) => !selectOption.get(child.key!)).length;
111110
addOrDel(child.parent.key, child.parent.label, selectCount === 0);
@@ -161,7 +160,7 @@ function Transfer(props: TransferProps) {
161160
<div className={cls} style={{ width: 400, ...style }}>
162161
<Card
163162
bodyStyle={{ padding: 5 }}
164-
title={`${leftSelectedKeys.length}/${selectedOptions.length}`}
163+
title={`${leftSelectedKeys.length}/${selectedOptionsShowCount.current}`}
165164
className={`${prefixCls}-card`}
166165
>
167166
{showSearch && (

0 commit comments

Comments
 (0)
Please sign in to comment.