Skip to content

Commit

Permalink
feat(module:icon): fix falsy render (#2912)
Browse files Browse the repository at this point in the history
* feat(module:icon): fix falsy render

* fix: remove redundant code
close #2911
  • Loading branch information
Wendell authored and vthinkxie committed Feb 18, 2019
1 parent a530f80 commit 6dd3cbf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
9 changes: 5 additions & 4 deletions components/collapse/demo/custom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import { Component } from '@angular/core';
selector: 'nz-demo-collapse-custom',
template: `
<nz-collapse [nzBordered]="false">
<nz-collapse-panel *ngFor="let panel of panels; let isFirst = first" [nzHeader]="panel.name" [nzActive]="panel.active"
<nz-collapse-panel #p *ngFor="let panel of panels; let isFirst = first" [nzHeader]="panel.name" [nzActive]="panel.active"
[ngStyle]="panel.customStyle" [nzExpandedIcon]="!isFirst && (panel.icon || expandedIcon)">
<p>{{panel.name}} content</p>
<ng-template #expandedIcon let-active>
{{ active }}
<i nz-icon type="caret-right" class="ant-collapse-arrow" [nzRotate]="p.nzActive ? 90 : -90"></i>
</ng-template>
</nz-collapse-panel>
<ng-template #expandedIcon>
<i nz-icon type="caret-right" class="ant-collapse-arrow"></i>
</ng-template>
</nz-collapse>
`,
styles : []
Expand Down
4 changes: 2 additions & 2 deletions components/collapse/nz-collapse-panel.component.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div role="tab" [attr.aria-expanded]="nzActive" class="ant-collapse-header" (click)="clickHeader()">
<ng-container *ngIf="nzShowArrow">
<ng-container *nzStringTemplateOutlet="nzExpandedIcon">
<i nz-icon [type]="nzExpandedIcon || 'right'" class="ant-collapse-arrow"></i>
<i nz-icon [type]="nzExpandedIcon || 'right'" class="ant-collapse-arrow" [nzRotate]="nzActive ? 90 : 0"></i>
</ng-container>
</ng-container>
<ng-container *nzStringTemplateOutlet="nzHeader">{{ nzHeader }}</ng-container>
Expand All @@ -12,4 +12,4 @@
<div class="ant-collapse-content-box">
<ng-content></ng-content>
</div>
</div>
</div>
13 changes: 10 additions & 3 deletions components/icon/nz-icon.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
OnChanges,
OnDestroy,
OnInit,
Renderer2
Renderer2,
SimpleChanges
} from '@angular/core';
import { IconDirective, ThemeType } from '@ant-design/icons-angular';
import { InputBoolean } from '../core/util';
Expand Down Expand Up @@ -135,6 +136,8 @@ export class NzIconDirective extends IconDirective implements OnInit, OnChanges,
private handleRotate(svg: SVGElement): void {
if (this.nzRotate) {
this.renderer.setAttribute(svg, 'style', `transform: rotate(${this.nzRotate}deg)`);
} else {
this.renderer.removeAttribute(svg, 'style');
}
}

Expand Down Expand Up @@ -162,9 +165,13 @@ export class NzIconDirective extends IconDirective implements OnInit, OnChanges,
super(iconService, elementRef, renderer);
}

ngOnChanges(): void {
if (!this.iconfont) {
ngOnChanges(changes: SimpleChanges): void {
const { type, nzType, nzTwotoneColor, twoToneColor, spin, nzSpin, theme, nzTheme, nzRotate } = changes;

if (type || nzType || nzTwotoneColor || twoToneColor || spin || nzSpin || theme || nzTheme) {
this.changeIcon2();
} else if (nzRotate) {
this.handleRotate(this.el.firstChild);
} else {
this._setSVGElement(this.iconService.createIconfontIcon(`#${this.iconfont}`));
}
Expand Down

0 comments on commit 6dd3cbf

Please sign in to comment.