@@ -3,6 +3,8 @@ import URI from "@ui5/webcomponents-base/src/types/URI";
3
3
import Bootstrap from "@ui5/webcomponents-base/src/Bootstrap" ;
4
4
import ShadowDOM from "@ui5/webcomponents-base/src/compatibility/ShadowDOM" ;
5
5
import { isIconURI } from "@ui5/webcomponents-base/src/IconPool" ;
6
+ import { isSpace , isEnter } from "@ui5/webcomponents-base/src/events/PseudoEvents" ;
7
+ import Function from "@ui5/webcomponents-base/src/types/Function" ;
6
8
import CardRenderer from "./build/compiled/CardRenderer.lit" ;
7
9
import Icon from "./Icon" ;
8
10
@@ -82,6 +84,34 @@ const metadata = {
82
84
type : URI ,
83
85
defaultValue : null ,
84
86
} ,
87
+
88
+ _headerActive : {
89
+ type : Boolean ,
90
+ } ,
91
+
92
+ _headerClick : {
93
+ type : Function ,
94
+ } ,
95
+
96
+ _headerKeydown : {
97
+ type : Function ,
98
+ } ,
99
+
100
+ _headerKeyup : {
101
+ type : Function ,
102
+ } ,
103
+ } ,
104
+ events : /** @lends sap.ui.webcomponents.main.Card.prototype */ {
105
+
106
+ /**
107
+ * Fired when the <code>ui5-card</code> header is pressed
108
+ * by click/tap or by using the Enter or Space key.
109
+ *
110
+ * @event
111
+ * @public
112
+ * @since 0.10.0
113
+ */
114
+ headerPress : { } ,
85
115
} ,
86
116
} ;
87
117
@@ -107,6 +137,14 @@ const metadata = {
107
137
* @public
108
138
*/
109
139
class Card extends WebComponent {
140
+ constructor ( ) {
141
+ super ( ) ;
142
+
143
+ this . _headerClick = this . headerClick . bind ( this ) ;
144
+ this . _headerKeydown = this . headerKeydown . bind ( this ) ;
145
+ this . _headerKeyup = this . headerKeyup . bind ( this ) ;
146
+ }
147
+
110
148
static get metadata ( ) {
111
149
return metadata ;
112
150
}
@@ -125,6 +163,12 @@ class Card extends WebComponent {
125
163
image,
126
164
ctr : state ,
127
165
renderIcon : state . icon && ! state . image ,
166
+ classes : {
167
+ header : {
168
+ "sapFCardHeader" : true ,
169
+ "sapFCardHeaderActive" : state . _headerActive ,
170
+ } ,
171
+ } ,
128
172
} ;
129
173
}
130
174
@@ -133,6 +177,36 @@ class Card extends WebComponent {
133
177
134
178
super . define ( ...params ) ;
135
179
}
180
+
181
+ headerClick ( ) {
182
+ this . fireEvent ( "headerPress" ) ;
183
+ }
184
+
185
+ headerKeydown ( event ) {
186
+ const enter = isEnter ( event ) ;
187
+ const space = isSpace ( event ) ;
188
+
189
+ this . _headerActive = enter || space ;
190
+
191
+ if ( enter ) {
192
+ this . fireEvent ( "headerPress" ) ;
193
+ return ;
194
+ }
195
+
196
+ if ( space ) {
197
+ event . preventDefault ( ) ;
198
+ }
199
+ }
200
+
201
+ headerKeyup ( event ) {
202
+ const space = isSpace ( event ) ;
203
+
204
+ this . _headerActive = false ;
205
+
206
+ if ( space ) {
207
+ this . fireEvent ( "headerPress" ) ;
208
+ }
209
+ }
136
210
}
137
211
138
212
Bootstrap . boot ( ) . then ( _ => {
0 commit comments