Skip to content

Commit

Permalink
fix(module:transfer): cancel selecting all should emit `nzSelectChang…
Browse files Browse the repository at this point in the history
…e` event (#8872)
  • Loading branch information
WwwHhhYran authored Nov 14, 2024
1 parent 9431d0d commit 5ff9821
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
1 change: 1 addition & 0 deletions components/transfer/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export interface TransferStat {
checkHalf: boolean;
checkCount: number;
shownCount: number;
availableCount: number;
}

export interface RenderListContext {
Expand Down
12 changes: 10 additions & 2 deletions components/transfer/transfer-list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import { NzTransferSearchComponent } from './transfer-search.component';
[nzChecked]="stat.checkAll"
(nzCheckedChange)="onItemSelectAll($event)"
[nzIndeterminate]="stat.checkHalf"
[nzDisabled]="stat.shownCount === 0 || disabled"
[nzDisabled]="stat.availableCount === 0 || disabled"
></label>
}
<span class="ant-transfer-list-header-selected">
Expand Down Expand Up @@ -175,13 +175,19 @@ export class NzTransferListComponent implements AfterViewInit {
checkAll: false,
checkHalf: false,
checkCount: 0,
shownCount: 0
shownCount: 0,
availableCount: 0
};

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

get availableData(): TransferItem[] {
// filter disabled data
return this.validData.filter(w => !w.disabled);
}

onItemSelect = (item: TransferItem): void => {
if (this.disabled || item.disabled) {
return;
Expand All @@ -206,6 +212,7 @@ export class NzTransferListComponent implements AfterViewInit {
const validCount = this.dataSource.filter(w => !w.disabled).length;
this.stat.checkCount = this.dataSource.filter(w => w.checked && !w.disabled).length;
this.stat.shownCount = this.validData.length;
this.stat.availableCount = this.availableData.length;
this.stat.checkAll = validCount > 0 && validCount === this.stat.checkCount;
this.stat.checkHalf = this.stat.checkCount > 0 && !this.stat.checkAll;
// Note: this is done explicitly since the internal `nzChecked` value may not be updated in edge cases.
Expand Down Expand Up @@ -233,6 +240,7 @@ export class NzTransferListComponent implements AfterViewInit {
item.hide = value.length > 0 && !this.matchFilter(value, item);
});
this.stat.shownCount = this.validData.length;
this.stat.availableCount = this.availableData.length;
this.filterChange.emit({ direction: this.direction, value });
}

Expand Down
7 changes: 2 additions & 5 deletions components/transfer/transfer.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,8 @@ export class NzTransferComponent implements OnInit, OnChanges, OnDestroy {

handleSelect(direction: TransferDirection, checked: boolean, item?: TransferItem): void {
const list = this.getCheckedData(direction);
if (list.every(i => i.disabled)) {
this.updateOperationStatus(direction, 0);
return;
}
this.updateOperationStatus(direction, list.length);
const count = list.filter(i => !i.disabled).length;
this.updateOperationStatus(direction, count);
this.nzSelectChange.emit({ direction, checked, list, item });
}

Expand Down
7 changes: 7 additions & 0 deletions components/transfer/transfer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,13 @@ describe('transfer', () => {
const selectorPath = '[data-direction="left"] .ant-transfer-list-header .ant-checkbox-disabled';
expect(pageObject.leftList.querySelectorAll(selectorPath).length).toBe(1);
});

it('should be disabled check all when all options are disabled', () => {
instance.nzDataSource = [{ title: `content`, disabled: true }];
fixture.detectChanges();
const cls = '[data-direction="left"] .ant-transfer-list-header .ant-checkbox-disabled';
expect(debugElement.queryAll(By.css(cls)).length).toBe(1);
});
});

it('#nzShowSelectAll', () => {
Expand Down

0 comments on commit 5ff9821

Please sign in to comment.