Skip to content

Commit c62d335

Browse files
author
Mikhail Bashkirov
committed
fix(icon): render nothing consistently when svg is undefined
1 parent 938e445 commit c62d335

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

packages/icon/src/LionIcon.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export class LionIcon extends LionLitElement {
8989
* so make sure to have <svg focusable="false"> in svg files
9090
*/
9191
_setSvg() {
92-
this.innerHTML = this.svg;
92+
this.innerHTML = this.svg ? this.svg : '';
9393
}
9494

9595
// TODO: find a better way to render dynamic icons without the need for unsafeHTML

packages/icon/test/lion-icon.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,16 @@ describe('lion-icon', () => {
149149

150150
expect(el.children[0].id).to.equal('svg-heart');
151151
});
152+
153+
it('does not render "undefined" if changed from valid input to undefined', async () => {
154+
const el = await fixture(
155+
html`
156+
<lion-icon .svg=${heartSvg}></lion-icon>
157+
`,
158+
);
159+
await el.updateComplete;
160+
el.svg = undefined;
161+
await el.updateComplete;
162+
expect(el.innerHTML).to.equal('');
163+
});
152164
});

0 commit comments

Comments
 (0)