@@ -4,6 +4,7 @@ import { getRTL } from "@ui5/webcomponents-base/dist/config/RTL.js";
44import { getIconData , getIconDataSync } from "@ui5/webcomponents-base/dist/SVGIconRegistry.js" ;
55import createStyleInHead from "@ui5/webcomponents-base/dist/util/createStyleInHead.js" ;
66import { fetchI18nBundle , getI18nBundle } from "@ui5/webcomponents-base/dist/i18nBundle.js" ;
7+ import { isSpace , isEnter } from "@ui5/webcomponents-base/dist/Keys.js" ;
78import IconTemplate from "./generated/templates/IconTemplate.lit.js" ;
89
910// Styles
@@ -17,6 +18,17 @@ const ICON_NOT_FOUND = "ICON_NOT_FOUND";
1718const metadata = {
1819 tag : "ui5-icon" ,
1920 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+
2032 /**
2133 * Defines the unique identifier (icon name) of each <code>ui5-icon</code>.
2234 * <br><br>
@@ -77,6 +89,13 @@ const metadata = {
7789 noAttribute : true ,
7890 } ,
7991
92+ /**
93+ * @private
94+ */
95+ focused : {
96+ type : Boolean ,
97+ } ,
98+
8099 /**
81100 * @private
82101 */
@@ -85,6 +104,14 @@ const metadata = {
85104 } ,
86105 } ,
87106 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+ } ,
88115 } ,
89116} ;
90117
@@ -137,6 +164,40 @@ class Icon extends UI5Element {
137164 await fetchI18nBundle ( "@ui5/webcomponents" ) ;
138165 }
139166
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+
140201 static createGlobalStyle ( ) {
141202 if ( ! window . ShadyDOM ) {
142203 return ;
0 commit comments