Skip to content
This repository has been archived by the owner on Nov 6, 2024. It is now read-only.

Commit

Permalink
Avoid calling .setElementClass with a value of undefined (#330)
Browse files Browse the repository at this point in the history
* Avoid calling `.setElementClass` with a value of undefined to prevent Angular Universal issues
* Simplify logic when adding/removing classes
  • Loading branch information
florianmrz authored and jfcere committed Jun 4, 2018
1 parent bee572c commit 6fff2ca
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
4 changes: 3 additions & 1 deletion lib/src/icon-mdi/icon-mdi.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ export class MzIconMdiDirective extends HandlePropChanges implements AfterViewIn
if (previousValue) {
this.renderer.setElementClass(this.elementRef.nativeElement, previousValue, false);
}
this.renderer.setElementClass(this.elementRef.nativeElement, this.align, !!this.align);
if (this.align) {
this.renderer.setElementClass(this.elementRef.nativeElement, this.align, true);
}
}

handleFlip(previousValue?: string) {
Expand Down
4 changes: 2 additions & 2 deletions lib/src/icon-mdi/icon-mdi.directive.unit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@ describe('MzIconMdiDirective:unit', () => {

it('should not add align css class when align is not provided', () => {

spyOn(renderer, 'setElementClass');
const spy = spyOn(renderer, 'setElementClass');

directive.handleAlign();

expect(renderer.setElementClass).toHaveBeenCalledWith(mockElementRef.nativeElement, directive.align, false);
expect(spy.calls.count()).toEqual(0);
});

it('should remove previous css class when provided', () => {
Expand Down
8 changes: 6 additions & 2 deletions lib/src/icon/icon.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ export class MzIconDirective extends HandlePropChanges implements AfterViewInit
if (previousValue) {
this.renderer.setElementClass(this.elementRef.nativeElement, previousValue, false);
}
this.renderer.setElementClass(this.elementRef.nativeElement, this.align, !!this.align);
if (this.align) {
this.renderer.setElementClass(this.elementRef.nativeElement, this.align, true);
}
}

handleIcon() {
Expand All @@ -53,6 +55,8 @@ export class MzIconDirective extends HandlePropChanges implements AfterViewInit
if (previousValue) {
this.renderer.setElementClass(this.elementRef.nativeElement, previousValue, false);
}
this.renderer.setElementClass(this.elementRef.nativeElement, this.size, !!this.size);
if (this.size) {
this.renderer.setElementClass(this.elementRef.nativeElement, this.size, true);
}
}
}
10 changes: 5 additions & 5 deletions lib/src/icon/icon.directive.unit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('MzIconDirective:unit', () => {

describe('initHandlers', () => {

it('should initilialize handlers correctly', () => {
it('should initialize handlers correctly', () => {

const handlers = {
align: 'handleAlign',
Expand Down Expand Up @@ -114,11 +114,11 @@ describe('MzIconDirective:unit', () => {

it('should not add align css class when align is not provided', () => {

spyOn(renderer, 'setElementClass');
const spy = spyOn(renderer, 'setElementClass');

directive.handleAlign();

expect(renderer.setElementClass).toHaveBeenCalledWith(mockElementRef.nativeElement, directive.align, false);
expect(spy.calls.count()).toEqual(0);
});

it('should remove previous css class when provided', () => {
Expand Down Expand Up @@ -162,11 +162,11 @@ describe('MzIconDirective:unit', () => {

it('should not add size css class when size is not provided', () => {

spyOn(renderer, 'setElementClass');
const spy = spyOn(renderer, 'setElementClass');

directive.handleSize();

expect(renderer.setElementClass).toHaveBeenCalledWith(mockElementRef.nativeElement, directive.size, false);
expect(spy.calls.count()).toEqual(0);
});

it('should remove previous css class when provided', () => {
Expand Down

0 comments on commit 6fff2ca

Please sign in to comment.