Skip to content

Commit 1204592

Browse files
jinchanzyouluna
authored andcommitted
fix(Transfer): fix wrong behavior of check-all while using search
1 parent e3c233a commit 1204592

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

src/transfer/view/transfer-panel.jsx

+23-10
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,16 @@ export default class TransferPanel extends Component {
120120
}
121121

122122
handleAllCheck(allChecked) {
123-
const { position, onChange } = this.props;
123+
const { position, onChange, filter } = this.props;
124+
const { searchedValue } = this.state;
124125

125126
let newValue;
126127
if (allChecked) {
127-
newValue = this.enabledDatasource.map(item => item.value);
128+
if (searchedValue) {
129+
newValue = this.enabledDatasource.filter(item => filter(searchedValue, item)).map(item => item.value);
130+
} else {
131+
newValue = this.enabledDatasource.map(item => item.value);
132+
}
128133
} else {
129134
newValue = [];
130135
}
@@ -280,12 +285,20 @@ export default class TransferPanel extends Component {
280285
);
281286
}
282287

283-
const { value, dataSource } = this.props;
288+
const { value, showSearch, filter, dataSource } = this.props;
289+
const { searchedValue } = this.state;
290+
let totalCount = dataSource.length;
291+
let _dataSource = dataSource;
284292
const checkedCount = value.length;
285-
const totalCount = dataSource.length;
286-
const totalEnabledCount = this.enabledDatasource.length;
293+
let _checkedCount = checkedCount;
294+
if (showSearch && searchedValue) {
295+
_dataSource = dataSource.filter(item => filter(searchedValue, item));
296+
totalCount = _dataSource.length;
297+
_checkedCount = _dataSource.filter(item => value.includes(item.value)).length;
298+
}
299+
const totalEnabledCount = Math.min(totalCount, this.enabledDatasource.length);
287300
const checked = checkedCount > 0 && checkedCount >= totalEnabledCount;
288-
const indeterminate = checkedCount > 0 && checkedCount < totalEnabledCount;
301+
const indeterminate = checkedCount > 0 && _checkedCount >= 0 && _checkedCount < totalEnabledCount;
289302
const items = totalCount > 1 ? locale.items : locale.item;
290303
const countLabel = checkedCount === 0 ? `${totalCount} ${items}` : `${checkedCount}/${totalCount} ${items}`;
291304

@@ -308,19 +321,19 @@ export default class TransferPanel extends Component {
308321
}
309322

310323
render() {
311-
const { prefix, title, showSearch, filter } = this.props;
324+
const { prefix, title, showSearch, filter, dataSource } = this.props;
312325
const { searchedValue } = this.state;
313-
let dataSource = this.props.dataSource;
326+
let _dataSource = this.props.dataSource;
314327
this.enabledDatasource = dataSource.filter(item => !item.disabled);
315328
if (showSearch && searchedValue) {
316-
dataSource = dataSource.filter(item => filter(searchedValue, item));
329+
_dataSource = dataSource.filter(item => filter(searchedValue, item));
317330
}
318331

319332
return (
320333
<div className={`${prefix}transfer-panel`}>
321334
{title ? this.renderHeader() : null}
322335
{showSearch ? this.renderSearch() : null}
323-
{this.renderList(dataSource)}
336+
{this.renderList(_dataSource)}
324337
{this.renderFooter()}
325338
</div>
326339
);

0 commit comments

Comments
 (0)