@@ -120,11 +120,16 @@ export default class TransferPanel extends Component {
120
120
}
121
121
122
122
handleAllCheck ( allChecked ) {
123
- const { position, onChange } = this . props ;
123
+ const { position, onChange, filter } = this . props ;
124
+ const { searchedValue } = this . state ;
124
125
125
126
let newValue ;
126
127
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
+ }
128
133
} else {
129
134
newValue = [ ] ;
130
135
}
@@ -280,12 +285,20 @@ export default class TransferPanel extends Component {
280
285
) ;
281
286
}
282
287
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 ;
284
292
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 ) ;
287
300
const checked = checkedCount > 0 && checkedCount >= totalEnabledCount ;
288
- const indeterminate = checkedCount > 0 && checkedCount < totalEnabledCount ;
301
+ const indeterminate = checkedCount > 0 && _checkedCount >= 0 && _checkedCount < totalEnabledCount ;
289
302
const items = totalCount > 1 ? locale . items : locale . item ;
290
303
const countLabel = checkedCount === 0 ? `${ totalCount } ${ items } ` : `${ checkedCount } /${ totalCount } ${ items } ` ;
291
304
@@ -308,19 +321,19 @@ export default class TransferPanel extends Component {
308
321
}
309
322
310
323
render ( ) {
311
- const { prefix, title, showSearch, filter } = this . props ;
324
+ const { prefix, title, showSearch, filter, dataSource } = this . props ;
312
325
const { searchedValue } = this . state ;
313
- let dataSource = this . props . dataSource ;
326
+ let _dataSource = this . props . dataSource ;
314
327
this . enabledDatasource = dataSource . filter ( item => ! item . disabled ) ;
315
328
if ( showSearch && searchedValue ) {
316
- dataSource = dataSource . filter ( item => filter ( searchedValue , item ) ) ;
329
+ _dataSource = dataSource . filter ( item => filter ( searchedValue , item ) ) ;
317
330
}
318
331
319
332
return (
320
333
< div className = { `${ prefix } transfer-panel` } >
321
334
{ title ? this . renderHeader ( ) : null }
322
335
{ showSearch ? this . renderSearch ( ) : null }
323
- { this . renderList ( dataSource ) }
336
+ { this . renderList ( _dataSource ) }
324
337
{ this . renderFooter ( ) }
325
338
</ div >
326
339
) ;
0 commit comments