fix(icon): render nothing consistently when svg is undefined

This commit is contained in:
Mikhail Bashkirov 2019-06-27 15:15:49 +02:00
parent 938e445781
commit c62d3353a2
2 changed files with 13 additions and 1 deletions

View file

@ -89,7 +89,7 @@ export class LionIcon extends LionLitElement {
* so make sure to have <svg focusable="false"> in svg files * so make sure to have <svg focusable="false"> in svg files
*/ */
_setSvg() { _setSvg() {
this.innerHTML = this.svg; this.innerHTML = this.svg ? this.svg : '';
} }
// TODO: find a better way to render dynamic icons without the need for unsafeHTML // TODO: find a better way to render dynamic icons without the need for unsafeHTML

View file

@ -149,4 +149,16 @@ describe('lion-icon', () => {
expect(el.children[0].id).to.equal('svg-heart'); expect(el.children[0].id).to.equal('svg-heart');
}); });
it('does not render "undefined" if changed from valid input to undefined', async () => {
const el = await fixture(
html`
<lion-icon .svg=${heartSvg}></lion-icon>
`,
);
await el.updateComplete;
el.svg = undefined;
await el.updateComplete;
expect(el.innerHTML).to.equal('');
});
}); });