@@ -4,6 +4,7 @@ import { getIconURI } from "@ui5/webcomponents-base/src/sap/ui/webcomponents/bas
4
4
import slideDown from "@ui5/webcomponents-base/src/sap/ui/webcomponents/base/animations/slideDown" ;
5
5
import slideUp from "@ui5/webcomponents-base/src/sap/ui/webcomponents/base/animations/slideUp" ;
6
6
import ShadowDOM from "@ui5/webcomponents-base/src/sap/ui/webcomponents/base/compatibility/ShadowDOM" ;
7
+ import { isSpace , isEnter } from "@ui5/webcomponents-base/src/sap/ui/webcomponents/base/events/PseudoEvents" ;
7
8
import PanelTemplateContext from "./PanelTemplateContext" ;
8
9
import BackgroundDesign from "./types/BackgroundDesign" ;
9
10
import PanelAccessibleRole from "./types/PanelAccessibleRole" ;
@@ -121,6 +122,9 @@ const metadata = {
121
122
_icon : {
122
123
type : Object ,
123
124
} ,
125
+ _header : {
126
+ type : Object ,
127
+ } ,
124
128
_contentExpanded : {
125
129
type : Boolean ,
126
130
} ,
@@ -206,23 +210,54 @@ class Panel extends WebComponent {
206
210
207
211
this . resourceBundle = getResourceBundle ( "@ui5/webcomponents" ) ;
208
212
213
+ this . _header = { } ;
214
+
209
215
this . _icon = { } ;
210
216
this . _icon . id = `${ this . id } -CollapsedImg` ;
211
217
this . _icon . src = getIconURI ( "navigation-right-arrow" ) ;
212
-
213
218
this . _icon . title = this . resourceBundle . getText ( "PANEL_ICON" ) ;
214
219
this . _icon . functional = true ;
215
- this . _icon . press = event => { event . preventDefault ( ) ; this . _toggleOpen ( ) ; } ;
220
+
221
+ this . _toggle = event => { event . preventDefault ( ) ; this . _toggleOpen ( ) ; } ;
222
+ this . _noOp = ( ) => { } ;
216
223
}
217
224
218
225
onBeforeRendering ( ) {
219
226
// If the animation is running, it will set the content expanded state at the end
220
227
if ( ! this . _animationRunning ) {
221
228
this . _contentExpanded = ! this . collapsed ;
222
229
}
230
+
231
+ const toggleWithInternalHeader = ! this . header ;
232
+ this . _header . press = toggleWithInternalHeader ? this . _toggle : this . _noOp ;
233
+ this . _icon . press = ! toggleWithInternalHeader ? this . _toggle : this . _noOp ;
234
+ }
235
+
236
+ onkeydown ( event ) {
237
+ const headerUsed = this . _headerOnTarget ( event . ui5target ) ;
238
+
239
+ if ( isEnter ( event ) && headerUsed ) {
240
+ this . _toggleOpen ( ) ;
241
+ }
242
+
243
+ if ( isSpace ( event ) && headerUsed ) {
244
+ event . preventDefault ( ) ;
245
+ }
246
+ }
247
+
248
+ onkeyup ( event ) {
249
+ const headerUsed = this . _headerOnTarget ( event . ui5target ) ;
250
+
251
+ if ( isSpace ( event ) && headerUsed ) {
252
+ this . _toggleOpen ( ) ;
253
+ }
223
254
}
224
255
225
256
_toggleOpen ( ) {
257
+ if ( this . fixed ) {
258
+ return ;
259
+ }
260
+
226
261
this . collapsed = ! this . collapsed ;
227
262
this . _animationRunning = true ;
228
263
@@ -252,6 +287,10 @@ class Panel extends WebComponent {
252
287
this . fireEvent ( "expand" , { } ) ;
253
288
}
254
289
290
+ _headerOnTarget ( target ) {
291
+ return target . classList . contains ( "sapMPanelWrappingDiv" ) ;
292
+ }
293
+
255
294
static async define ( ...params ) {
256
295
await fetchResourceBundle ( "@ui5/webcomponents" ) ;
257
296
0 commit comments