Skip to content

Commit

Permalink
fix(affix,anchor): wrong value is set when the initial value is non-n…
Browse files Browse the repository at this point in the history
…umber (#5277)
  • Loading branch information
hsuanxyz authored May 14, 2020
1 parent bac4bc4 commit 1c72939
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
11 changes: 5 additions & 6 deletions components/affix/affix.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,17 @@ export class NzAffixComponent implements AfterViewInit, OnChanges, OnDestroy {

@ViewChild('fixedEl', { static: true }) private fixedEl!: ElementRef<HTMLDivElement>;

// TODO@hsuanxyz SSR breaks (perhaps)?
@Input() nzTarget: string | Element | Window = window;
@Input() nzTarget?: string | Element | Window;

@Input()
@WithConfig<number | null>(NZ_CONFIG_COMPONENT_NAME)
@InputNumber()
nzOffsetTop: null | number = null;
@InputNumber(undefined)
nzOffsetTop?: null | number;

@Input()
@WithConfig<number | null>(NZ_CONFIG_COMPONENT_NAME)
@InputNumber()
nzOffsetBottom: null | number = null;
@InputNumber(undefined)
nzOffsetBottom?: null | number;

@Output() readonly nzChange = new EventEmitter<boolean>();

Expand Down
7 changes: 4 additions & 3 deletions components/affix/affix.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ describe('affix', () => {
});

it('recreate bug https://github.com/NG-ZORRO/ng-zorro-antd/issues/868', fakeAsync(() => {
context.newOffset = offsetTop.toString();
// tslint:disable-next-line:no-any
context.newOffset = offsetTop.toString() as any;
setupInitialState({ offsetTop: offsetTop + 1 });
emitScroll(window, 2);

Expand Down Expand Up @@ -503,6 +504,6 @@ describe('affix-extra', () => {
class TestAffixComponent {
@ViewChild(NzAffixComponent, { static: true }) nzAffixComponent!: NzAffixComponent;
fakeTarget: string | Element | Window | null = null;
newOffset: {} = {};
newOffsetBottom: {} = {};
newOffset!: number;
newOffsetBottom!: number;
}
2 changes: 1 addition & 1 deletion components/anchor/anchor.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export class NzAnchorComponent implements OnDestroy, AfterViewInit, OnChanges {
nzBounds: number = 5;

@Input()
@InputNumber()
@InputNumber(undefined)
@WithConfig<number>(NZ_CONFIG_COMPONENT_NAME)
nzOffsetTop?: number = undefined;

Expand Down
4 changes: 2 additions & 2 deletions components/core/util/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,6 @@ export function InputCssPixel(): NzSafeAny {
return propDecoratorFactory('InputCssPixel', toCssPixel);
}

export function InputNumber(): NzSafeAny {
return propDecoratorFactory('InputNumber', toNumber);
export function InputNumber(fallbackValue?: NzSafeAny): NzSafeAny {
return propDecoratorFactory('InputNumber', (value: string | number) => toNumber(value, fallbackValue));
}

0 comments on commit 1c72939

Please sign in to comment.