@@ -64,6 +64,17 @@ const metadata = {
64
64
type : String ,
65
65
} ,
66
66
67
+ /**
68
+ * Defines if the <code>ui5-card</code> header would be interactive,
69
+ * e.g gets hover effect, gets focused and <code>headerPress</code> event is fired, when it is pressed.
70
+ * @type {boolean }
71
+ * @defaultvalue false
72
+ * @public
73
+ */
74
+ headerInteractive : {
75
+ type : Boolean ,
76
+ } ,
77
+
67
78
/**
68
79
* Defines image source URI or built-in icon font URI.
69
80
* </br></br>
@@ -75,7 +86,6 @@ const metadata = {
75
86
*/
76
87
avatar : {
77
88
type : String ,
78
- defaultValue : null ,
79
89
} ,
80
90
81
91
_headerActive : {
@@ -87,7 +97,8 @@ const metadata = {
87
97
/**
88
98
* Fired when the <code>ui5-card</code> header is pressed
89
99
* by click/tap or by using the Enter or Space key.
90
- *
100
+ * <br><br>
101
+ * <b>Note:</b> The event would be fired only if the <code>headerInteractive</code> property is set to true.
91
102
* @event
92
103
* @public
93
104
* @since 0.10.0
@@ -106,6 +117,9 @@ const metadata = {
106
117
* The header can be used through several properties, such as:
107
118
* <code>heading</code>, <code>subtitle</code>, <code>status</code> and <code>avatar</code>.
108
119
*
120
+ * <h3>Keyboard handling</h3>
121
+ * In case you enable <code>headerInteractive</cdoe> property, you can press the <code>ui5-card</code> header by Space and Enter keys.
122
+ *
109
123
* <h3>ES6 Module Import</h3>
110
124
*
111
125
* <code>import "@ui5/webcomponents/dist/Card";</code>
@@ -142,7 +156,8 @@ class Card extends UI5Element {
142
156
} ,
143
157
header : {
144
158
"sapFCardHeader" : true ,
145
- "sapFCardHeaderActive" : this . _headerActive ,
159
+ "sapFCardHeaderInteractive" : this . headerInteractive ,
160
+ "sapFCardHeaderActive" : this . headerInteractive && this . _headerActive ,
146
161
} ,
147
162
} ;
148
163
}
@@ -155,17 +170,31 @@ class Card extends UI5Element {
155
170
return ! ! this . avatar && ! this . icon ;
156
171
}
157
172
173
+ get role ( ) {
174
+ return this . headerInteractive ? "button" : undefined ;
175
+ }
176
+
177
+ get tabindex ( ) {
178
+ return this . headerInteractive ? "0" : undefined ;
179
+ }
180
+
158
181
static async define ( ...params ) {
159
182
await Icon . define ( ) ;
160
183
161
184
super . define ( ...params ) ;
162
185
}
163
186
164
187
_headerClick ( ) {
165
- this . fireEvent ( "headerPress" ) ;
188
+ if ( this . headerInteractive ) {
189
+ this . fireEvent ( "headerPress" ) ;
190
+ }
166
191
}
167
192
168
193
_headerKeydown ( event ) {
194
+ if ( ! this . headerInteractive ) {
195
+ return ;
196
+ }
197
+
169
198
const enter = isEnter ( event ) ;
170
199
const space = isSpace ( event ) ;
171
200
@@ -182,6 +211,10 @@ class Card extends UI5Element {
182
211
}
183
212
184
213
_headerKeyup ( event ) {
214
+ if ( ! this . headerInteractive ) {
215
+ return ;
216
+ }
217
+
185
218
const space = isSpace ( event ) ;
186
219
187
220
this . _headerActive = false ;
0 commit comments