File tree 4 files changed +34
-0
lines changed
4 files changed +34
-0
lines changed Original file line number Diff line number Diff line change 8
8
dir =" {{ dir }} "
9
9
tabindex =" -1"
10
10
@keydown ={{ _onkeydown }}
11
+ @focusout ={{ _onfocusout }}
11
12
>
12
13
13
14
<span class =" first-fe" data-ui5-focus-trap tabindex =" 0" @focusin ={{ forwardToLast }} ></span >
Original file line number Diff line number Diff line change @@ -263,6 +263,13 @@ class Popup extends UI5Element {
263
263
}
264
264
}
265
265
266
+ _onfocusout ( e ) {
267
+ // relatedTarget is the element, which will get focus. If no such element exists, focus the root
268
+ if ( ! e . relatedTarget ) {
269
+ this . _root . focus ( ) ;
270
+ }
271
+ }
272
+
266
273
/**
267
274
* Focus trapping
268
275
* @private
Original file line number Diff line number Diff line change 384
384
385
385
< br >
386
386
387
+ < ui5-button id ="btnOpenPopoverWithDiv "> Open Popover with div Inside</ ui5-button >
388
+
389
+ < ui5-popover id ="popWithDiv " header-text ="Newsletter subscription " modal >
390
+ < div id ="divContent "> I'm a div, which can't get focus. Click me and see where focus goes.</ div >
391
+ < div slot ="footer " class ="popover-footer ">
392
+ < ui5-button design ="Emphasized "> Subscribe</ ui5-button >
393
+ </ div >
394
+ </ ui5-popover >
395
+
387
396
< script >
388
397
btn . addEventListener ( "click" , function ( event ) {
389
398
pop . openBy ( btn ) ;
488
497
489
498
popover . openBy ( btnOpenDynamic ) ;
490
499
} ) ;
500
+
501
+ btnOpenPopoverWithDiv . addEventListener ( "click" , function ( event ) {
502
+ popWithDiv . openBy ( event . target ) ;
503
+ } ) ;
504
+
491
505
</ script >
492
506
</ body >
493
507
Original file line number Diff line number Diff line change @@ -251,6 +251,18 @@ describe("Popover general interaction", () => {
251
251
assert . ok ( activeElementId , popoverId , "Popover remains focused" ) ;
252
252
} ) ;
253
253
254
+ it ( "tests focus when content, which can't be focused is clicked" , ( ) => {
255
+ browser . url ( "http://localhost:8080/test-resources/pages/Popover.html" ) ;
256
+
257
+ $ ( "#btnOpenPopoverWithDiv" ) . click ( ) ;
258
+ $ ( "#divContent" ) . click ( ) ;
259
+
260
+ const popoverId = "popWithDiv" ;
261
+ const activeElementId = $ ( browser . getActiveElement ( ) ) . getAttribute ( "id" ) ;
262
+
263
+ assert . strictEqual ( activeElementId , popoverId , "Popover is focused" ) ;
264
+ } ) ;
265
+
254
266
it ( "tests that dynamically created popover is opened" , ( ) => {
255
267
browser . url ( "http://localhost:8080/test-resources/pages/Popover.html" ) ;
256
268
You can’t perform that action at this time.
0 commit comments