Skip to content

Commit 0587236

Browse files
authored
fix(transfer): add trackBy to the list and track by the hide property (#7424)
1 parent 21e15e6 commit 0587236

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

components/transfer/transfer-list.component.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import { TransferDirection, TransferItem } from './interface';
3434
<ng-template #defaultRenderList>
3535
<ul *ngIf="stat.shownCount > 0" class="ant-transfer-list-content">
3636
<li
37-
*ngFor="let item of validData"
37+
*ngFor="let item of validData; trackBy: trackByHide"
3838
(click)="onItemSelect(item)"
3939
class="ant-transfer-list-content-item"
4040
[ngClass]="{ 'ant-transfer-list-content-item-disabled': disabled || item.disabled }"
@@ -164,6 +164,12 @@ export class NzTransferListComponent implements AfterViewInit {
164164
return this.dataSource.filter(w => !w.hide);
165165
}
166166

167+
trackByHide(_index: number, item: TransferItem): boolean | undefined {
168+
// The `validData` is a getter which returns new array each time the property is read.
169+
// This may lead to unexpected re-renders, tho the array hasn't been updated.
170+
return item.hide;
171+
}
172+
167173
onItemSelect = (item: TransferItem): void => {
168174
if (this.disabled || item.disabled) {
169175
return;

0 commit comments

Comments
 (0)