Skip to content

Commit

Permalink
fix(transfer): add trackBy to the list and track by the hide prop…
Browse files Browse the repository at this point in the history
…erty (#7424)
  • Loading branch information
arturovt authored Jul 25, 2022
1 parent 21e15e6 commit 0587236
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion components/transfer/transfer-list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { TransferDirection, TransferItem } from './interface';
<ng-template #defaultRenderList>
<ul *ngIf="stat.shownCount > 0" class="ant-transfer-list-content">
<li
*ngFor="let item of validData"
*ngFor="let item of validData; trackBy: trackByHide"
(click)="onItemSelect(item)"
class="ant-transfer-list-content-item"
[ngClass]="{ 'ant-transfer-list-content-item-disabled': disabled || item.disabled }"
Expand Down Expand Up @@ -164,6 +164,12 @@ export class NzTransferListComponent implements AfterViewInit {
return this.dataSource.filter(w => !w.hide);
}

trackByHide(_index: number, item: TransferItem): boolean | undefined {
// The `validData` is a getter which returns new array each time the property is read.
// This may lead to unexpected re-renders, tho the array hasn't been updated.
return item.hide;
}

onItemSelect = (item: TransferItem): void => {
if (this.disabled || item.disabled) {
return;
Expand Down

0 comments on commit 0587236

Please sign in to comment.