@@ -4,6 +4,7 @@ import { getRTL } from "@ui5/webcomponents-base/dist/config/RTL.js";
4
4
import { getIconData , getIconDataSync } from "@ui5/webcomponents-base/dist/SVGIconRegistry.js" ;
5
5
import createStyleInHead from "@ui5/webcomponents-base/dist/util/createStyleInHead.js" ;
6
6
import { fetchI18nBundle , getI18nBundle } from "@ui5/webcomponents-base/dist/i18nBundle.js" ;
7
+ import { isSpace , isEnter } from "@ui5/webcomponents-base/dist/Keys.js" ;
7
8
import IconTemplate from "./generated/templates/IconTemplate.lit.js" ;
8
9
9
10
// Styles
@@ -17,6 +18,17 @@ const ICON_NOT_FOUND = "ICON_NOT_FOUND";
17
18
const metadata = {
18
19
tag : "ui5-icon" ,
19
20
properties : /** @lends sap.ui.webcomponents.main.Icon.prototype */ {
21
+ /**
22
+ * Defines if the icon is interactive (focusable and pressable)
23
+ * @type {boolean }
24
+ * @defaultvalue false
25
+ * @public
26
+ * @since 1.0.0-rc.8
27
+ */
28
+ interactive : {
29
+ type : Boolean ,
30
+ } ,
31
+
20
32
/**
21
33
* Defines the unique identifier (icon name) of each <code>ui5-icon</code>.
22
34
* <br><br>
@@ -77,6 +89,13 @@ const metadata = {
77
89
noAttribute : true ,
78
90
} ,
79
91
92
+ /**
93
+ * @private
94
+ */
95
+ focused : {
96
+ type : Boolean ,
97
+ } ,
98
+
80
99
/**
81
100
* @private
82
101
*/
@@ -85,6 +104,14 @@ const metadata = {
85
104
} ,
86
105
} ,
87
106
events : {
107
+ /**
108
+ * Fired on mouseup, space and enter if icon is interactive
109
+ * @private
110
+ * @since 1.0.0-rc.8
111
+ */
112
+ click : {
113
+
114
+ } ,
88
115
} ,
89
116
} ;
90
117
@@ -137,6 +164,40 @@ class Icon extends UI5Element {
137
164
await fetchI18nBundle ( "@ui5/webcomponents" ) ;
138
165
}
139
166
167
+ _onfocusin ( event ) {
168
+ if ( this . interactive ) {
169
+ this . focused = true ;
170
+ }
171
+ }
172
+
173
+ _onfocusout ( event ) {
174
+ this . focused = false ;
175
+ }
176
+
177
+ _onkeydown ( event ) {
178
+ if ( this . interactive && isEnter ( event ) ) {
179
+ this . fireEvent ( "click" ) ;
180
+ }
181
+ }
182
+
183
+ _onkeyup ( event ) {
184
+ if ( this . interactive && isSpace ( event ) ) {
185
+ this . fireEvent ( "click" ) ;
186
+ }
187
+ }
188
+
189
+ _onclick ( event ) {
190
+ if ( this . interactive ) {
191
+ event . preventDefault ( ) ;
192
+ // Prevent the native event and fire custom event because otherwise the noConfict event won't be thrown
193
+ this . fireEvent ( "click" ) ;
194
+ }
195
+ }
196
+
197
+ get tabIndex ( ) {
198
+ return this . interactive ? "0" : "-1" ;
199
+ }
200
+
140
201
static createGlobalStyle ( ) {
141
202
if ( ! window . ShadyDOM ) {
142
203
return ;
0 commit comments