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

feat(module:*): support for Angular ivy #3740

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions components/affix/affix.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -483,8 +483,7 @@ describe('affix-extra', () => {
left: 5,
width: 200,
height: 20
// tslint:disable-next-line:no-any
} as any);
} as DOMRect);
window.dispatchEvent(new Event('scroll'));
tick(30);
fixture.detectChanges();
Expand Down
43 changes: 18 additions & 25 deletions components/affix/nz-affix.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,35 +46,14 @@ export const NZ_AFFIX_DEFAULT_SCROLL_TIME = 20;
})
export class NzAffixComponent implements AfterViewInit, OnChanges, OnDestroy {
@Input() nzTarget: string | Element | Window;

@Input()
set nzOffsetTop(value: number | null) {
if (value === undefined || value === null) {
return;
}
this._offsetTop = toNumber(value, null);
this.updatePosition({} as Event);
}

get nzOffsetTop(): number | null {
return this._offsetTop;
}

@Input()
set nzOffsetBottom(value: number) {
if (typeof value === 'undefined') {
return;
}
this._offsetBottom = toNumber(value, null);
this.updatePosition({} as Event);
}

@Input() nzOffsetTop: number | null;
@Input() nzOffsetBottom: number | null;
@Output() readonly nzChange = new EventEmitter<boolean>();
@ViewChild('fixedEl', { static: true }) private fixedEl: ElementRef<HTMLDivElement>;

private timeout: number;
private scroll$: Subscription | null = null;
private readonly events = ['resize', 'scroll', 'touchstart', 'touchmove', 'touchend', 'pageshow', 'load'];
@ViewChild('fixedEl', { static: true }) private fixedEl: ElementRef<HTMLDivElement>;
private readonly placeholderNode: HTMLElement;
private affixStyle: NgStyleInterface | undefined;
private placeholderStyle: NgStyleInterface | undefined;
Expand All @@ -98,6 +77,20 @@ export class NzAffixComponent implements AfterViewInit, OnChanges, OnDestroy {
}

ngOnChanges(changes: SimpleChanges): void {
if (changes.nzOffsetTop) {
const value = changes.nzOffsetTop.currentValue;
if (value !== undefined && value !== null) {
this._offsetTop = toNumber(value, null);
this.updatePosition({} as Event);
}
}
if (changes.nzOffsetBottom) {
const value = changes.nzOffsetBottom.currentValue;
if (value !== undefined) {
this._offsetBottom = toNumber(value, null);
this.updatePosition({} as Event);
}
}
if (changes.nzTarget) {
this.registerListeners();
}
Expand Down Expand Up @@ -232,7 +225,7 @@ export class NzAffixComponent implements AfterViewInit, OnChanges, OnDestroy {
}
const targetNode = this.target as (HTMLElement | Window);
// Backwards support
let offsetTop = this.nzOffsetTop;
let offsetTop = this._offsetTop;
const scrollTop = this.scrollSrv.getScroll(targetNode!, true);
const elemOffset = this.getOffset(this.placeholderNode, targetNode!);
const fixedNode = this.fixedEl.nativeElement;
Expand Down
1 change: 1 addition & 0 deletions components/auto-complete/nz-autocomplete.component.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<ng-template>
<div class="ant-select-dropdown ant-select-dropdown--single ant-select-dropdown-placement-bottomLeft"
#panel
[@.disabled]="noAnimation?.nzNoAnimation"
[nzNoAnimation]="noAnimation?.nzNoAnimation"
[@slideMotion]="dropDownPosition"
[class.ant-select-dropdown-hidden]="!showPanel" [ngClass]="nzOverlayClassName" [ngStyle]="nzOverlayStyle">
Expand Down
15 changes: 14 additions & 1 deletion components/auto-complete/nz-autocomplete.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@ import { Directionality } from '@angular/cdk/bidi';
import { DOWN_ARROW, ENTER, ESCAPE, TAB, UP_ARROW } from '@angular/cdk/keycodes';
import { OverlayContainer } from '@angular/cdk/overlay';
import { ScrollDispatcher } from '@angular/cdk/scrolling';
import { ChangeDetectionStrategy, Component, NgZone, OnInit, QueryList, ViewChild, ViewChildren } from '@angular/core';
import {
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
NgZone,
OnInit,
QueryList,
ViewChild,
ViewChildren
} from '@angular/core';
import { async, fakeAsync, flush, inject, tick, ComponentFixture, TestBed } from '@angular/core/testing';
import { FormsModule, FormBuilder, FormControl, FormGroup, ReactiveFormsModule } from '@angular/forms';
import { By } from '@angular/platform-browser';
Expand Down Expand Up @@ -816,6 +825,7 @@ describe('auto-complete', () => {
Promise.resolve().then(() => {
fixture.detectChanges();
flush();
fixture.detectChanges();
const panel = overlayContainerElement.querySelector('.ant-select-dropdown') as HTMLElement;
expect(panel.classList).not.toContain('ant-select-dropdown-hidden');
});
Expand Down Expand Up @@ -910,9 +920,12 @@ class NzTestAutocompleteWithOnPushDelayComponent implements OnInit {
options: string[] = [];
@ViewChild(NzAutocompleteTriggerDirective, { static: false }) trigger: NzAutocompleteTriggerDirective;

constructor(private cdr: ChangeDetectorRef) {}

ngOnInit(): void {
setTimeout(() => {
this.options = ['One'];
this.cdr.markForCheck();
}, 1000);
}
}
Expand Down
2 changes: 1 addition & 1 deletion components/avatar/demo/dynamic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ const colorList = ['#f56a00', '#7265e6', '#ffbf00', '#00a2ae'];
selector: 'nz-demo-avatar-dynamic',
template: `
<nz-avatar
[ngStyle]="{ 'background-color': color }"
[nzText]="text"
nzSize="large"
[ngStyle]="{ 'background-color': color }"
style="vertical-align: middle;"
></nz-avatar>
<button nz-button [nzType]="'dashed'" (click)="change()" style="margin-left: 16px; vertical-align: middle;">
Expand Down
3 changes: 2 additions & 1 deletion components/avatar/demo/module
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { NzAvatarModule } from 'ng-zorro-antd/avatar';
import { NzBadgeModule } from 'ng-zorro-antd/badge';
import { NzButtonModule } from 'ng-zorro-antd/button';
import { CommonModule } from '@angular/common';

export const moduleList = [ NzAvatarModule, NzBadgeModule, NzButtonModule ];
export const moduleList = [ CommonModule, NzAvatarModule, NzBadgeModule, NzButtonModule ];
1 change: 1 addition & 0 deletions components/cascader/nz-cascader.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
[class.ant-cascader-menus-hidden]="!menuVisible"
[ngClass]="menuCls"
[ngStyle]="nzMenuStyle"
[@.disabled]="noAnimation?.nzNoAnimation"
[nzNoAnimation]="noAnimation?.nzNoAnimation"
[@slideMotion]="dropDownPosition"
(mouseleave)="onTriggerMouseLeave($event)">
Expand Down
5 changes: 1 addition & 4 deletions components/core/no-animation/nz-no-animation.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ const DISABLED_CLASSNAME = 'nz-animate-disabled';

@Directive({
selector: '[nzNoAnimation]',
exportAs: 'nzNoAnimation',
host: {
'[@.disabled]': 'nzNoAnimation'
}
exportAs: 'nzNoAnimation'
})
export class NzNoAnimationDirective implements OnChanges, AfterViewInit {
@Input() @InputBoolean() nzNoAnimation: boolean = false;
Expand Down
14 changes: 4 additions & 10 deletions components/date-picker/nz-date-picker.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,10 +384,8 @@ describe('NzDatePickerComponent', () => {
fixture.detectChanges();
expect(nzOnChange).toHaveBeenCalled();
expect(nzOnCalendarChange).not.toHaveBeenCalled();
// @ts-ignore
// tslint:disable-next-line:no-any
const result = nzOnChange.calls.allArgs()[0][0] as any;
expect(result!.getDate()).toBe(+cellText);
const result = (nzOnChange.calls.allArgs()[0] as Date[])[0];
expect(result.getDate()).toBe(+cellText);
}));
});

Expand Down Expand Up @@ -745,9 +743,7 @@ describe('NzDatePickerComponent', () => {
fixture.detectChanges();
tick(500);
fixture.detectChanges();
// @ts-ignore
// tslint:disable-next-line:no-any
const result = nzOnChange.calls.allArgs()[0][0] as any;
const result = (nzOnChange.calls.allArgs()[0] as Date[])[0];
expect(isSameDay(new Date(), result)).toBeTruthy();
expect(queryFromOverlay('.ant-calendar-picker-container')).toBeFalsy(); // Should closed
}));
Expand Down Expand Up @@ -814,9 +810,7 @@ describe('NzDatePickerComponent', () => {
flush();
fixture.detectChanges();
expect(nzOnChange).toHaveBeenCalled();
// @ts-ignore
// tslint:disable-next-line:no-any
const result = nzOnChange.calls.allArgs()[0][0] as any;
const result = (nzOnChange.calls.allArgs()[0] as Date[])[0];
expect(result.getDate()).toBe(22);
}));
}); // /specified date picker testing
Expand Down
4 changes: 1 addition & 3 deletions components/date-picker/nz-month-picker.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,7 @@ describe('NzMonthPickerComponent', () => {
tick(500);
fixture.detectChanges();
expect(nzOnChange).toHaveBeenCalled();
// @ts-ignore
// tslint:disable-next-line:no-any
const result = nzOnChange.calls.allArgs()[0][0] as any;
const result = (nzOnChange.calls.allArgs()[0] as Date[])[0];
expect(result.getMonth() + 1).toBe(parseInt(cellText, 10));
}));
}); // /general api testing
Expand Down
25 changes: 9 additions & 16 deletions components/date-picker/nz-range-picker.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,21 +275,18 @@ describe('NzRangePickerComponent', () => {
tick(500);
fixture.detectChanges();
expect(nzOnCalendarChange).toHaveBeenCalled();
// @ts-ignore
// tslint:disable-next-line:no-any
let result = nzOnCalendarChange.calls.allArgs()[0][0] as any;
expect(result[0].getDate()).toBe(+leftText);
let result = (nzOnCalendarChange.calls.allArgs()[0] as Date[][])[0];
expect((result[0] as Date).getDate()).toBe(+leftText);
const right = getFirstCell('right');
const rightText = right.textContent!.trim();
dispatchMouseEvent(right, 'click');
fixture.detectChanges();
tick(500);
fixture.detectChanges();
expect(nzOnCalendarChange).toHaveBeenCalled();
// @ts-ignore
result = nzOnCalendarChange.calls.allArgs()[1][0];
expect(result[0].getDate()).toBe(+leftText);
expect(result[1].getDate()).toBe(+rightText);
result = (nzOnCalendarChange.calls.allArgs()[1] as Date[][])[0];
expect((result[0] as Date).getDate()).toBe(+leftText);
expect((result[1] as Date).getDate()).toBe(+rightText);
}));

it('should support nzOnChange', fakeAsync(() => {
Expand All @@ -311,11 +308,9 @@ describe('NzRangePickerComponent', () => {
tick(500);
fixture.detectChanges();
expect(nzOnChange).toHaveBeenCalled();
// @ts-ignore
// tslint:disable-next-line:no-any
const result = nzOnChange.calls.allArgs()[0][0] as any;
expect(result[0].getDate()).toBe(+leftText);
expect(result[1].getDate()).toBe(+rightText);
const result = (nzOnChange.calls.allArgs()[0] as Date[][])[0];
expect((result[0] as Date).getDate()).toBe(+leftText);
expect((result[1] as Date).getDate()).toBe(+rightText);
}));
}); // /general api testing

Expand Down Expand Up @@ -681,9 +676,7 @@ describe('NzRangePickerComponent', () => {
fixture.detectChanges();
tick(500);
expect(nzOnChange).toHaveBeenCalled();
// @ts-ignore
// tslint:disable-next-line:no-any
const result = nzOnChange.calls.allArgs()[0][0] as any;
const result = (nzOnChange.calls.allArgs()[0] as Date[][])[0];
expect(result[0].getDate()).toBe(11);
expect(result[1].getDate()).toBe(12);
}));
Expand Down
4 changes: 1 addition & 3 deletions components/date-picker/nz-year-picker.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,7 @@ describe('NzYearPickerComponent', () => {
tick(500);
fixture.detectChanges();
expect(nzOnChange).toHaveBeenCalled();
// @ts-ignore
// tslint:disable-next-line:no-any
const result = nzOnChange.calls.allArgs()[0][0] as any;
const result = (nzOnChange.calls.allArgs()[0] as Date[])[0];
expect(result.getFullYear()).toBe(parseInt(cellText, 10));
}));
}); // /general api testing
Expand Down
1 change: 1 addition & 0 deletions components/dropdown/nz-dropdown-button.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
(positionChange)="onPositionChange($event)"
[cdkConnectedOverlayOpen]="nzVisible">
<div class="{{'ant-dropdown ant-dropdown-placement-'+nzPlacement}}"
[@.disabled]="noAnimation?.nzNoAnimation"
[nzNoAnimation]="noAnimation?.nzNoAnimation"
[@slideMotion]="dropDownPosition"
(mouseenter)="setVisibleStateWhen(true,'hover')"
Expand Down
1 change: 1 addition & 0 deletions components/dropdown/nz-dropdown-menu.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[ngClass]="nzOverlayClassName"
[ngStyle]="nzOverlayStyle"
[@slideMotion]="dropDownPosition"
[@.disabled]="noAnimation?.nzNoAnimation"
[nzNoAnimation]="noAnimation?.nzNoAnimation"
(mouseenter)="setVisibleStateWhen(true,'hover')"
(mouseleave)="setVisibleStateWhen(false,'hover')">
Expand Down
1 change: 1 addition & 0 deletions components/dropdown/nz-dropdown.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
[ngClass]="nzOverlayClassName"
[ngStyle]="nzOverlayStyle"
[@slideMotion]="dropDownPosition"
[@.disabled]="noAnimation?.nzNoAnimation"
[nzNoAnimation]="noAnimation?.nzNoAnimation"
[style.minWidth.px]="triggerWidth"
(mouseenter)="setVisibleStateWhen(true,'hover')"
Expand Down
3 changes: 2 additions & 1 deletion components/input/demo/module
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ import { NzDatePickerModule } from 'ng-zorro-antd/date-picker';
import { NzIconModule } from 'ng-zorro-antd/icon';
import { NzToolTipModule } from 'ng-zorro-antd/tooltip';
import { NzButtonModule } from 'ng-zorro-antd/button';
import { FormsModule } from '@angular/forms';

export const moduleList = [ NzInputModule, NzSelectModule, NzCascaderModule, NzInputNumberModule, NzDatePickerModule, NzIconModule, NzToolTipModule, NzButtonModule ];
export const moduleList = [ FormsModule, NzInputModule, NzSelectModule, NzCascaderModule, NzInputNumberModule, NzDatePickerModule, NzIconModule, NzToolTipModule, NzButtonModule ];
2 changes: 1 addition & 1 deletion components/input/demo/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import { Component, ElementRef, ViewChild, ViewEncapsulation } from '@angular/co
nzTrigger="focus"
nzPlacement="topLeft"
nzOverlayClassName="numeric-input"
[ngModel]="value"
[nzTitle]="title"
placeholder="Input a number"
[ngModel]="value"
(ngModelChange)="onChange($event)"
(blur)="onBlur()"
/>
Expand Down
2 changes: 1 addition & 1 deletion components/layout/nz-sider.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*ngIf="isSiderTrigger"
(click)="toggleCollapse()"
[style.width]="widthSetting">
<ng-template [ngTemplateOutlet]="nzTrigger"></ng-template>
<ng-template [ngTemplateOutlet]="trigger"></ng-template>
</div>
<ng-template #defaultTrigger>
<i nz-icon [nzType]="nzCollapsed ? 'right' : 'left'" *ngIf="!nzReverseArrow"></i>
Expand Down
14 changes: 10 additions & 4 deletions components/layout/nz-sider.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,22 @@ export class NzSiderComponent implements OnInit, AfterViewInit, OnDestroy {
xl: '1200px',
xxl: '1600px'
};

@Output() readonly nzCollapsedChange = new EventEmitter();

@Input() nzWidth: string | number = 200;
@Input() nzTheme: 'light' | 'dark' = 'dark';
@Input() nzCollapsedWidth = 80;
@Input() nzBreakpoint: NzBreakPoint;
@Input() nzZeroTrigger: TemplateRef<void>;
@Input() @ViewChild('defaultTrigger', { static: true }) nzTrigger: TemplateRef<void>;
@Input() @InputBoolean() nzReverseArrow = false;
@Input() @InputBoolean() nzCollapsible = false;
@Input() @InputBoolean() nzCollapsed = false;
@Output() readonly nzCollapsedChange = new EventEmitter();
@Input() nzTrigger: TemplateRef<void>;
@ViewChild('defaultTrigger', { static: true }) defaultTrigger: TemplateRef<void>;
get trigger(): TemplateRef<void> {
return this.nzTrigger !== undefined ? this.nzTrigger : this.defaultTrigger;
}

get flexSetting(): string {
return `0 0 ${this.widthSetting}`;
Expand Down Expand Up @@ -108,14 +114,14 @@ export class NzSiderComponent implements OnInit, AfterViewInit, OnDestroy {
get isZeroTrigger(): boolean {
return (
this.nzCollapsible &&
this.nzTrigger &&
this.trigger &&
this.nzCollapsedWidth === 0 &&
((this.nzBreakpoint && this.below) || !this.nzBreakpoint)
);
}

get isSiderTrigger(): boolean {
return this.nzCollapsible && this.nzTrigger && this.nzCollapsedWidth !== 0;
return this.nzCollapsible && this.trigger && this.nzCollapsedWidth !== 0;
}

constructor(
Expand Down
2 changes: 2 additions & 0 deletions components/menu/nz-submenu.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
</div>
<ul *ngIf="nzMenuService.mode === 'inline'"
[@collapseMotion]="expandState"
[@.disabled]="noAnimation?.nzNoAnimation"
[nzNoAnimation]="noAnimation?.nzNoAnimation"
[ngClass]="nzMenuClassName"
class="ant-menu ant-menu-inline ant-menu-sub">
Expand All @@ -32,6 +33,7 @@
<div class="ant-menu-submenu ant-menu-submenu-popup"
[@slideMotion]="expandState"
[@zoomBigMotion]="expandState"
[@.disabled]="noAnimation?.nzNoAnimation"
[nzNoAnimation]="noAnimation?.nzNoAnimation"
[class.ant-menu-light]="nzMenuService.theme === 'light'"
[class.ant-menu-dark]="nzMenuService.theme === 'dark'"
Expand Down
Loading