Skip to content

Commit 964af67

Browse files
authored
fix: icon no longer flickers on IE (#722)
1 parent 52517c4 commit 964af67

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

packages/main/src/Icon.js

+19
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import UI5Element from "@ui5/webcomponents-base/dist/UI5Element.js";
22
import litRender from "@ui5/webcomponents-base/dist/renderer/LitRenderer.js";
33
import { getRTL } from "@ui5/webcomponents-base/dist/config/RTL.js";
44
import { getIconData } from "@ui5/webcomponents-base/dist/SVGIconRegistry.js";
5+
import createStyleInHead from "@ui5/webcomponents-base/dist/util/createStyleInHead.js";
56
import { fetchResourceBundle, getResourceBundle } from "@ui5/webcomponents-base/dist/ResourceBundle.js";
67
import IconTemplate from "./generated/templates/IconTemplate.lit.js";
78

@@ -111,11 +112,22 @@ class Icon extends UI5Element {
111112
}
112113

113114
static async define(...params) {
115+
this.createGlobalStyle();
114116
await fetchResourceBundle("@ui5/webcomponents");
115117

116118
super.define(...params);
117119
}
118120

121+
static createGlobalStyle() {
122+
if (!window.ShadyDOM) {
123+
return;
124+
}
125+
const styleElement = document.head.querySelector(`style[data-ui5-icon-global]`);
126+
if (!styleElement) {
127+
createStyleInHead(`ui5-icon:not([data-ui5-defined]) { display: none !important; }`, { "data-ui5-icon-global": "" });
128+
}
129+
}
130+
119131
_normalizeIconURI(iconURI) {
120132
return this._hasIconPrefix(iconURI) ? iconURI : `sap-icon://${iconURI}`;
121133
}
@@ -148,6 +160,13 @@ class Icon extends UI5Element {
148160
get dir() {
149161
return getRTL() ? "rtl" : "ltr";
150162
}
163+
164+
onEnterDOM() {
165+
if (!window.ShadyDOM) {
166+
return;
167+
}
168+
this.setAttribute("data-ui5-defined", "");
169+
}
151170
}
152171

153172
Icon.define();

packages/main/test/sap/ui/webcomponents/main/pages/Simple.html

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
<body>
3131

3232
<ui5-button>ivan</ui5-button>
33+
<ui5-icon src="sap-icon://add"></ui5-icon>
3334

3435
</body>
3536
</html>

0 commit comments

Comments
 (0)