Skip to content

Commit 3b6bdec

Browse files
authored
fix(module: list): fix the bug that synchrone action item are not displayed in the item (#7958)
* fix(module:list): load asynchrone-list-action * fix(module:list): wrong import * fix(module:list): wrong import
1 parent d26870f commit 3b6bdec

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

components/list/list-item-cell.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ import {
1616
ViewChild
1717
} from '@angular/core';
1818
import { defer, merge, MonoTypeOperatorFunction, Observable, of, Subject } from 'rxjs';
19-
import { switchMap, take, takeUntil } from 'rxjs/operators';
19+
import { exhaustMap, startWith, take, takeUntil } from 'rxjs/operators';
2020

2121
import { NzDestroyService } from 'ng-zorro-antd/core/services';
22+
import { NzSafeAny } from 'ng-zorro-antd/core/types';
2223

2324
@Component({
2425
selector: 'nz-list-item-extra, [nz-list-item-extra]',
@@ -62,14 +63,14 @@ export class NzListItemActionsComponent implements OnChanges {
6263

6364
actions: Array<TemplateRef<void>> = [];
6465
private inputActionChanges$ = new Subject<null>();
65-
private contentChildrenChanges$: Observable<null> = defer(() => {
66+
private contentChildrenChanges$: Observable<NzSafeAny> = defer(() => {
6667
if (this.nzListItemActions) {
6768
return of(null);
6869
}
6970
return this.ngZone.onStable.pipe(
7071
take(1),
7172
this.enterZone(),
72-
switchMap(() => this.contentChildrenChanges$)
73+
exhaustMap(() => this.nzListItemActions.changes.pipe(startWith(this.nzListItemActions)))
7374
);
7475
});
7576

components/list/list.spec.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { BidiModule, Dir } from '@angular/cdk/bidi';
22
import { Component, DebugElement, TemplateRef, ViewChild } from '@angular/core';
3-
import { ComponentFixture, TestBed } from '@angular/core/testing';
3+
import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
44
import { By } from '@angular/platform-browser';
5+
import { Observable, timer } from 'rxjs';
6+
import { map } from 'rxjs/operators';
57

68
import { ComponentBed, createComponentBed } from 'ng-zorro-antd/core/testing/component-bed';
79
import { NzIconTestModule } from 'ng-zorro-antd/icon/testing';
@@ -163,6 +165,11 @@ describe('list', () => {
163165
expect(dl.query(By.css('.ant-list-item-main')) != null).toBe(true);
164166
expect(dl.query(By.css('.ant-list-item-extra')) != null).toBe(true);
165167
});
168+
it('should display the asynchronous action', fakeAsync(() => {
169+
tick(2000);
170+
fixture.detectChanges();
171+
expect(dl.query(By.css('.ant-list-item-action')) != null).toBe(true);
172+
}));
166173
});
167174

168175
describe('item', () => {
@@ -259,6 +266,9 @@ describe('list RTL', () => {
259266
nzAvatar="https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png"
260267
nzDescription="Ant Design, a design language for background applications, is refined by Ant UED Team"
261268
></nz-list-item-meta>
269+
<ul nz-list-item-actions>
270+
<nz-list-item-action *ngFor="let action of actions$ | async">{{ action }}</nz-list-item-action>
271+
</ul>
262272
</nz-list-item>
263273
</ng-template>
264274
<ng-template #loadMore>
@@ -290,6 +300,7 @@ class TestListComponent {
290300
];
291301
// eslint-disable-next-line @typescript-eslint/no-explicit-any
292302
nzGrid: any = { gutter: 16, span: 12 };
303+
actions$: Observable<string[]> = timer(500).pipe(map(() => ['Edit', 'Delete']));
293304
}
294305

295306
@Component({

0 commit comments

Comments
 (0)