Skip to content

Commit df13b0d

Browse files
authored
Merge pull request #133 from Naaajii/bugfix/undefined-properties
Bugfix/undefined properties
2 parents 7438882 + 94855a0 commit df13b0d

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

projects/ngneat/svg-icon/src/lib/svg-icon.component.spec.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,39 @@ describe('SvgIconComponent', () => {
5151
expect(host.element.style.color).toBe('var(--svg-icon-color, red)');
5252
});
5353

54+
it('should not assign falsy height', () => {
55+
host = createHost(`<svg-icon [key]="key" [height]="height"></svg-icon>`, {
56+
hostProps: {
57+
key: 'dashboard',
58+
height: undefined,
59+
},
60+
});
61+
62+
expect(host.element.style.height).toBe('');
63+
});
64+
65+
it('should not assign falsy width', () => {
66+
host = createHost(`<svg-icon [key]="key" [width]="width"></svg-icon>`, {
67+
hostProps: {
68+
key: 'dashboard',
69+
width: undefined,
70+
},
71+
});
72+
73+
expect(host.element.style.width).toBe('');
74+
});
75+
76+
it('should not assign falsy color', () => {
77+
host = createHost(`<svg-icon [key]="key" [color]="color"></svg-icon>`, {
78+
hostProps: {
79+
key: 'dashboard',
80+
color: undefined,
81+
},
82+
});
83+
84+
expect(host.element.style.color).toBe('');
85+
});
86+
5487
it('should change font size', () => {
5588
host = createHost(`<svg-icon [key]="key" [fontSize]="fontSize"></svg-icon>`, {
5689
hostProps: {

projects/ngneat/svg-icon/src/lib/svg-icon.component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,15 @@ export class SvgIconComponent {
6868
this.setIconSize(this.mergedConfig.sizes[this.mergedConfig.defaultSize || 'md']!);
6969
}
7070

71-
if (changes.width) {
71+
if (changes.width?.currentValue) {
7272
this.element.style.width = `var(--svg-icon-width, ${coerceCssPixelValue(this.width)})`;
7373
}
7474

75-
if (changes.height) {
75+
if (changes.height?.currentValue) {
7676
this.element.style.height = `var(--svg-icon-height, ${coerceCssPixelValue(this.height)})`;
7777
}
7878

79-
if (changes.color) {
79+
if (changes.color?.currentValue) {
8080
this.element.style.color = `var(--svg-icon-color, ${this.color})`;
8181
}
8282

0 commit comments

Comments
 (0)