@@ -3,6 +3,7 @@ import { getRTL } from "@ui5/webcomponents-base/dist/config/RTL.js";
3
3
import UI5Element from "@ui5/webcomponents-base/dist/UI5Element.js" ;
4
4
import { getFirstFocusableElement , getLastFocusableElement } from "@ui5/webcomponents-base/dist/util/FocusableElements.js" ;
5
5
import createStyleInHead from "@ui5/webcomponents-base/dist/util/createStyleInHead.js" ;
6
+ import { isTabPrevious } from "@ui5/webcomponents-base/dist/Keys.js" ;
6
7
import PopupTemplate from "./generated/templates/PopupTemplate.lit.js" ;
7
8
import PopupBlockLayer from "./generated/templates/PopupBlockLayerTemplate.lit.js" ;
8
9
import { getNextZIndex , getFocusedElement , isFocusedElementWithinNode } from "./popup-utils/PopupUtils.js" ;
@@ -242,6 +243,12 @@ class Popup extends UI5Element {
242
243
} ) ;
243
244
}
244
245
246
+ _onkeydown ( e ) {
247
+ if ( e . target === this . _root && isTabPrevious ( e ) ) {
248
+ e . preventDefault ( ) ;
249
+ }
250
+ }
251
+
245
252
/**
246
253
* Focus trapping
247
254
* @private
@@ -251,6 +258,8 @@ class Popup extends UI5Element {
251
258
252
259
if ( firstFocusable ) {
253
260
firstFocusable . focus ( ) ;
261
+ } else {
262
+ this . _root . focus ( ) ;
254
263
}
255
264
}
256
265
@@ -263,6 +272,8 @@ class Popup extends UI5Element {
263
272
264
273
if ( lastFocusable ) {
265
274
lastFocusable . focus ( ) ;
275
+ } else {
276
+ this . _root . focus ( ) ;
266
277
}
267
278
}
268
279
@@ -284,7 +295,8 @@ class Popup extends UI5Element {
284
295
285
296
const element = this . getRootNode ( ) . getElementById ( this . initialFocus )
286
297
|| document . getElementById ( this . initialFocus )
287
- || await getFirstFocusableElement ( this ) ;
298
+ || await getFirstFocusableElement ( this )
299
+ || this . _root ; // in case of no focusable content focus the root
288
300
289
301
if ( element ) {
290
302
element . focus ( ) ;
@@ -468,6 +480,10 @@ class Popup extends UI5Element {
468
480
return this . ariaLabel || undefined ;
469
481
}
470
482
483
+ get _root ( ) {
484
+ return this . shadowRoot . querySelector ( ".ui5-popup-root" ) ;
485
+ }
486
+
471
487
get dir ( ) {
472
488
return getRTL ( ) ? "rtl" : "ltr" ;
473
489
}
@@ -484,8 +500,12 @@ class Popup extends UI5Element {
484
500
485
501
get classes ( ) {
486
502
return {
487
- root : { } ,
488
- content : { } ,
503
+ root : {
504
+ "ui5-popup-root" : true ,
505
+ } ,
506
+ content : {
507
+ "ui5-popup-content" : true ,
508
+ } ,
489
509
} ;
490
510
}
491
511
}
0 commit comments