Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(module:timeline): when the data clear, reset items #7109

Merged
merged 1 commit into from Dec 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions components/timeline/timeline.component.ts
Expand Up @@ -151,6 +151,9 @@ export class NzTimelineComponent implements AfterContentInit, OnChanges, OnDestr

this.timelineItems = this.nzReverse ? this.listOfItems.toArray().reverse() : this.listOfItems.toArray();
this.hasLabelItem = hasLabelItem;
} else {
this.timelineItems = [];
this.hasLabelItem = false;
}

this.cdr.markForCheck();
Expand Down
38 changes: 38 additions & 0 deletions components/timeline/timeline.spec.ts
Expand Up @@ -245,6 +245,27 @@ describe('nz-timeline', () => {
expect(timeline.nativeElement.firstElementChild!.classList).not.toContain('ant-timeline-rtl');
});
});

describe('clear', () => {
let testBed: ComponentBed<NzTestTimelineClearItemsComponent>;
let fixture: ComponentFixture<NzTestTimelineClearItemsComponent>;
let timeline: NzTimelineComponent;

beforeEach(() => {
testBed = createComponentBed(NzTestTimelineClearItemsComponent, {
imports: [NzTimelineModule]
});
fixture = testBed.fixture;
fixture.detectChanges();
timeline = fixture.componentInstance.nzTimeLine;
});

it('test clear items', () => {
fixture.componentInstance.reset();
fixture.detectChanges();
expect(timeline.timelineItems.length).toBe(0);
});
});
});

@Component({
Expand Down Expand Up @@ -314,3 +335,20 @@ export class NzTestTimelineRtlComponent {
@ViewChild(Dir) dir!: Dir;
direction = 'rtl';
}

@Component({
template: `
<nz-timeline nzMode="custom">
<nz-timeline-item *ngFor="let item of data">{{ item }}</nz-timeline-item>
</nz-timeline>
<span (click)="reset()">reset</span>
`
})
export class NzTestTimelineClearItemsComponent {
@ViewChild(NzTimelineComponent)
nzTimeLine!: NzTimelineComponent;
data = [1, 2, 3];
reset(): void {
this.data = [];
}
}