Skip to content

Commit

Permalink
fix(carousel): resize content after window resized (#1815)
Browse files Browse the repository at this point in the history
close #1811
  • Loading branch information
Wendell authored and vthinkxie committed Jul 22, 2018
1 parent 6117f20 commit 88b0915
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions components/carousel/nz-carousel.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
ElementRef,
EventEmitter,
HostBinding,
HostListener,
Input,
OnDestroy,
Output,
Expand Down Expand Up @@ -72,6 +73,11 @@ export class NzCarouselComponent implements AfterViewInit, OnDestroy, AfterConte
@Output() nzAfterChange: EventEmitter<number> = new EventEmitter();
@Output() nzBeforeChange: EventEmitter<{ from: number; to: number }> = new EventEmitter();

@HostListener('window:resize', [ '$event' ])
onWindowResize(e: UIEvent): void {
this.renderContent();
}

get nextIndex(): number {
return this.activeIndex < this.slideContents.length - 1 ? (this.activeIndex + 1) : 0;
}
Expand Down
6 changes: 6 additions & 0 deletions components/carousel/nz-carousel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@ describe('carousel', () => {
fixture.detectChanges();
expect(carouselContents[ 2 ].nativeElement.classList).toContain('slick-active');
});
it('should resize content after window resized', fakeAsync(() => {
const resizeSpy = spyOn(testComponent.nzCarouselComponent, 'renderContent');
window.dispatchEvent(new Event('resize'));
tick(200);
expect(resizeSpy).toHaveBeenCalled();
}));
});
});

Expand Down

0 comments on commit 88b0915

Please sign in to comment.