Skip to content

Commit 9a5ca2a

Browse files
committed
make last attempt to retrieve icon at firstUpdated, this is relevant in light-dom contexts
1 parent c2212c1 commit 9a5ca2a

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

packages/uui-icon/lib/uui-icon.element.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export class UUIIconElement extends LitElement {
2828
];
2929

3030
private _name: string | null = null;
31+
private _retrievedNameIcon: boolean = false;
3132

3233
@state()
3334
private _nameSvg: string | null = null;
@@ -45,7 +46,9 @@ export class UUIIconElement extends LitElement {
4546
}
4647
set name(newValue) {
4748
this._name = newValue;
48-
this.requestIcon();
49+
if (this.shadowRoot) {
50+
this.requestIcon();
51+
}
4952
}
5053
private requestIcon() {
5154
if (this._name !== '' && this._name !== null) {
@@ -54,11 +57,13 @@ export class UUIIconElement extends LitElement {
5457
});
5558
this.dispatchEvent(event);
5659
if (event.icon !== null) {
60+
this._retrievedNameIcon = true;
5761
event.icon.then((iconSvg: string) => {
5862
this._useFallback = false;
5963
this._nameSvg = iconSvg;
6064
});
6165
} else {
66+
this._retrievedNameIcon = false;
6267
this._useFallback = true;
6368
}
6469
}
@@ -87,15 +92,20 @@ export class UUIIconElement extends LitElement {
8792

8893
connectedCallback() {
8994
super.connectedCallback();
90-
if (this._name !== '' && this._name !== null) {
91-
if (this._nameSvg === null) {
92-
this.requestIcon();
93-
}
95+
if (this._retrievedNameIcon === false) {
96+
this.requestIcon();
9497
}
9598
}
9699

97100
disconnectedCallback(): void {
98-
this._nameSvg = null;
101+
this._retrievedNameIcon = false;
102+
}
103+
104+
firstUpdated() {
105+
// Registry might not have been created then this icon was connected, so therefor we will make another attempt to retrieve the icon.
106+
if (this._retrievedNameIcon === false) {
107+
this.requestIcon();
108+
}
99109
}
100110

101111
render() {

0 commit comments

Comments
 (0)