Skip to content

Commit 5ff9821

Browse files
authored
fix(module:transfer): cancel selecting all should emit nzSelectChange event (#8872)
1 parent 9431d0d commit 5ff9821

File tree

4 files changed

+20
-7
lines changed

4 files changed

+20
-7
lines changed

components/transfer/interface.ts

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export interface TransferStat {
4444
checkHalf: boolean;
4545
checkCount: number;
4646
shownCount: number;
47+
availableCount: number;
4748
}
4849

4950
export interface RenderListContext {

components/transfer/transfer-list.component.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import { NzTransferSearchComponent } from './transfer-search.component';
4444
[nzChecked]="stat.checkAll"
4545
(nzCheckedChange)="onItemSelectAll($event)"
4646
[nzIndeterminate]="stat.checkHalf"
47-
[nzDisabled]="stat.shownCount === 0 || disabled"
47+
[nzDisabled]="stat.availableCount === 0 || disabled"
4848
></label>
4949
}
5050
<span class="ant-transfer-list-header-selected">
@@ -175,13 +175,19 @@ export class NzTransferListComponent implements AfterViewInit {
175175
checkAll: false,
176176
checkHalf: false,
177177
checkCount: 0,
178-
shownCount: 0
178+
shownCount: 0,
179+
availableCount: 0
179180
};
180181

181182
get validData(): TransferItem[] {
182183
return this.dataSource.filter(w => !w.hide);
183184
}
184185

186+
get availableData(): TransferItem[] {
187+
// filter disabled data
188+
return this.validData.filter(w => !w.disabled);
189+
}
190+
185191
onItemSelect = (item: TransferItem): void => {
186192
if (this.disabled || item.disabled) {
187193
return;
@@ -206,6 +212,7 @@ export class NzTransferListComponent implements AfterViewInit {
206212
const validCount = this.dataSource.filter(w => !w.disabled).length;
207213
this.stat.checkCount = this.dataSource.filter(w => w.checked && !w.disabled).length;
208214
this.stat.shownCount = this.validData.length;
215+
this.stat.availableCount = this.availableData.length;
209216
this.stat.checkAll = validCount > 0 && validCount === this.stat.checkCount;
210217
this.stat.checkHalf = this.stat.checkCount > 0 && !this.stat.checkAll;
211218
// Note: this is done explicitly since the internal `nzChecked` value may not be updated in edge cases.
@@ -233,6 +240,7 @@ export class NzTransferListComponent implements AfterViewInit {
233240
item.hide = value.length > 0 && !this.matchFilter(value, item);
234241
});
235242
this.stat.shownCount = this.validData.length;
243+
this.stat.availableCount = this.availableData.length;
236244
this.filterChange.emit({ direction: this.direction, value });
237245
}
238246

components/transfer/transfer.component.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -245,11 +245,8 @@ export class NzTransferComponent implements OnInit, OnChanges, OnDestroy {
245245

246246
handleSelect(direction: TransferDirection, checked: boolean, item?: TransferItem): void {
247247
const list = this.getCheckedData(direction);
248-
if (list.every(i => i.disabled)) {
249-
this.updateOperationStatus(direction, 0);
250-
return;
251-
}
252-
this.updateOperationStatus(direction, list.length);
248+
const count = list.filter(i => !i.disabled).length;
249+
this.updateOperationStatus(direction, count);
253250
this.nzSelectChange.emit({ direction, checked, list, item });
254251
}
255252

components/transfer/transfer.spec.ts

+7
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,13 @@ describe('transfer', () => {
247247
const selectorPath = '[data-direction="left"] .ant-transfer-list-header .ant-checkbox-disabled';
248248
expect(pageObject.leftList.querySelectorAll(selectorPath).length).toBe(1);
249249
});
250+
251+
it('should be disabled check all when all options are disabled', () => {
252+
instance.nzDataSource = [{ title: `content`, disabled: true }];
253+
fixture.detectChanges();
254+
const cls = '[data-direction="left"] .ant-transfer-list-header .ant-checkbox-disabled';
255+
expect(debugElement.queryAll(By.css(cls)).length).toBe(1);
256+
});
250257
});
251258

252259
it('#nzShowSelectAll', () => {

0 commit comments

Comments
 (0)