@@ -2,6 +2,7 @@ import UI5Element from "@ui5/webcomponents-base/dist/UI5Element.js";
2
2
import litRender from "@ui5/webcomponents-base/dist/renderer/LitRenderer.js" ;
3
3
import { getRTL } from "@ui5/webcomponents-base/dist/config/RTL.js" ;
4
4
import { getIconData } from "@ui5/webcomponents-base/dist/SVGIconRegistry.js" ;
5
+ import { fetchResourceBundle , getResourceBundle } from "@ui5/webcomponents-base/dist/ResourceBundle.js" ;
5
6
import IconTemplate from "./generated/templates/IconTemplate.lit.js" ;
6
7
7
8
// Styles
@@ -30,6 +31,31 @@ const metadata = {
30
31
src : {
31
32
type : String ,
32
33
} ,
34
+
35
+ /**
36
+ * Defines the text alternative of the <code>ui5-icon</code>.
37
+ * If not provided a default text alternative will be set, if present.
38
+ * <br><br>
39
+ * <b>Note:</b> Every icon should have a text alternative in order to
40
+ * calculate its accessible name.
41
+ *
42
+ * @type {string }
43
+ * @public
44
+ */
45
+ accessibleName : {
46
+ type : String ,
47
+ } ,
48
+
49
+ /**
50
+ * Defines whether the <code>ui5-icon</code> should have a tooltip.
51
+ *
52
+ * @type {boolean }
53
+ * @defaultvalue false
54
+ * @public
55
+ */
56
+ showTooltip : {
57
+ type : Boolean ,
58
+ } ,
33
59
} ,
34
60
events : {
35
61
} ,
@@ -63,6 +89,11 @@ const metadata = {
63
89
* @public
64
90
*/
65
91
class Icon extends UI5Element {
92
+ constructor ( ) {
93
+ super ( ) ;
94
+ this . resourceBundle = getResourceBundle ( "@ui5/webcomponents" ) ;
95
+ }
96
+
66
97
static get metadata ( ) {
67
98
return metadata ;
68
99
}
@@ -79,6 +110,12 @@ class Icon extends UI5Element {
79
110
return iconCss ;
80
111
}
81
112
113
+ static async define ( ...params ) {
114
+ await fetchResourceBundle ( "@ui5/webcomponents" ) ;
115
+
116
+ super . define ( ...params ) ;
117
+ }
118
+
82
119
_normalizeIconURI ( iconURI ) {
83
120
return this . _hasIconPrefix ( iconURI ) ? iconURI : `sap-icon://${ iconURI } ` ;
84
121
}
@@ -98,6 +135,16 @@ class Icon extends UI5Element {
98
135
return icon . d ;
99
136
}
100
137
138
+ get hasIconTooltip ( ) {
139
+ return this . showTooltip && this . accessibleNameText ;
140
+ }
141
+
142
+ get accessibleNameText ( ) {
143
+ const icon = getIconData ( this . _normalizeIconURI ( this . src ) ) ;
144
+
145
+ return this . accessibleName || ( icon . accData && this . resourceBundle . getText ( icon . accData ) ) ;
146
+ }
147
+
101
148
get dir ( ) {
102
149
return getRTL ( ) ? "rtl" : "ltr" ;
103
150
}
0 commit comments