Skip to content

Commit

Permalink
refactor(module:anchor): remove deprecated APIs for v10 (#5776)
Browse files Browse the repository at this point in the history
BREAKING CHANGES:

- `nzTarget` has been removed, use `nzContainer` instead.
  • Loading branch information
hsuanxyz authored Sep 15, 2020
1 parent 7e64e4c commit e50d530
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
11 changes: 3 additions & 8 deletions components/anchor/anchor.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
ViewEncapsulation
} from '@angular/core';
import { NzConfigKey, NzConfigService, WithConfig } from 'ng-zorro-antd/core/config';
import { warnDeprecation } from 'ng-zorro-antd/core/logger';
import { NzScrollService } from 'ng-zorro-antd/core/services';
import { BooleanInput, NgStyleInterface, NumberInput, NzSafeAny } from 'ng-zorro-antd/core/types';
import { InputBoolean, InputNumber } from 'ng-zorro-antd/core/util';
Expand Down Expand Up @@ -91,7 +90,6 @@ export class NzAnchorComponent implements OnDestroy, AfterViewInit, OnChanges {
nzOffsetTop?: number = undefined;

@Input() nzContainer?: string | HTMLElement;
@Input() nzTarget: string | HTMLElement = '';

@Output() readonly nzClick = new EventEmitter<string>();
@Output() readonly nzScroll = new EventEmitter<NzAnchorLinkComponent>();
Expand Down Expand Up @@ -234,19 +232,16 @@ export class NzAnchorComponent implements OnDestroy, AfterViewInit, OnChanges {
}

ngOnChanges(changes: SimpleChanges): void {
const { nzOffsetTop, nzTarget, nzContainer } = changes;
const { nzOffsetTop, nzContainer } = changes;
if (nzOffsetTop) {
this.wrapperStyle = {
'max-height': `calc(100vh - ${this.nzOffsetTop}px)`
};
}
if (nzContainer || nzTarget) {
const container = this.nzContainer || this.nzTarget;
if (nzContainer) {
const container = this.nzContainer;
this.container = typeof container === 'string' ? this.doc.querySelector(container) : container;
this.registerScrollEvent();
if (nzTarget) {
warnDeprecation(`'nzTarget' of 'nz-anchor' is deprecated and will be removed in 10.0.0.Please use 'nzContainer' instead.`);
}
}
}
}
10 changes: 5 additions & 5 deletions components/anchor/anchor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,18 +152,18 @@ describe('anchor', () => {
});
});

describe('[nzTarget]', () => {
describe('[nzContainer]', () => {
it('with window', () => {
spyOn(window, 'addEventListener');
context.nzTarget = window;
context.nzContainer = window;
fixture.detectChanges();
expect(window.addEventListener).toHaveBeenCalled();
});
it('with string', () => {
spyOn(context, '_click');
const el = document.querySelector('#target')!;
spyOn(el, 'addEventListener');
context.nzTarget = '#target';
context.nzContainer = '#target';
fixture.detectChanges();
expect(el.addEventListener).toHaveBeenCalled();
page.to('#basic-target');
Expand Down Expand Up @@ -235,7 +235,7 @@ describe('anchor', () => {
[nzBounds]="nzBounds"
[nzShowInkInFixed]="nzShowInkInFixed"
[nzOffsetTop]="nzOffsetTop"
[nzTarget]="nzTarget"
[nzContainer]="nzContainer"
(nzClick)="_click($event)"
(nzScroll)="_scroll($event)"
>
Expand Down Expand Up @@ -291,7 +291,7 @@ export class TestComponent {
nzBounds = 5;
nzOffsetTop = 0;
nzShowInkInFixed = false;
nzTarget: any = null;
nzContainer: any = null;
_click() {}
_scroll() {}
}
14 changes: 14 additions & 0 deletions schematics/ng-update/data/input-names.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@ export const inputNames: VersionChanges<InputNameUpgradeData> = {
]
}
],
[ TargetVersion.V10 ]: [
{
pr: 'https://github.com/NG-ZORRO/ng-zorro-antd/pull/5776',
changes: [
{
replace : 'nzTarget',
replaceWith: 'nzContainer',
whitelist : {
elements: [ 'nz-anchor' ]
}
}
]
}
],
[ TargetVersion.V9 ]: [
{
pr : 'https://github.com/NG-ZORRO/ng-zorro-antd/pull/3909',
Expand Down

0 comments on commit e50d530

Please sign in to comment.