Skip to content

Commit 6930ad5

Browse files
dimovpetarilhan007
authored andcommitted
fix(ui5-popup): correct focus when there is no focusable content (#2583)
1 parent f05c4bf commit 6930ad5

4 files changed

Lines changed: 18 additions & 15 deletions

File tree

packages/main/src/Popover.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -685,17 +685,6 @@ class Popover extends Popup {
685685
};
686686
}
687687

688-
get classes() {
689-
return {
690-
root: {
691-
"ui5-popup-root": true,
692-
},
693-
content: {
694-
"ui5-popup-content": true,
695-
},
696-
};
697-
}
698-
699688
/**
700689
* Hook for descendants to hide header.
701690
*/

packages/main/src/Popup.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,8 @@ class Popup extends UI5Element {
266266

267267
if (firstFocusable) {
268268
firstFocusable.focus();
269+
} else {
270+
this._root.focus();
269271
}
270272
}
271273

@@ -278,6 +280,8 @@ class Popup extends UI5Element {
278280

279281
if (lastFocusable) {
280282
lastFocusable.focus();
283+
} else {
284+
this._root.focus();
281285
}
282286
}
283287

@@ -299,7 +303,8 @@ class Popup extends UI5Element {
299303

300304
const element = this.getRootNode().getElementById(this.initialFocus)
301305
|| document.getElementById(this.initialFocus)
302-
|| await getFirstFocusableElement(this);
306+
|| await getFirstFocusableElement(this)
307+
|| this._root; // in case of no focusable content focus the root
303308

304309
if (element) {
305310
element.focus();
@@ -486,6 +491,10 @@ class Popup extends UI5Element {
486491
return this.ariaLabel || undefined;
487492
}
488493

494+
get _root() {
495+
return this.shadowRoot.querySelector(".ui5-popup-root");
496+
}
497+
489498
get dir() {
490499
return getRTL() ? "rtl" : "ltr";
491500
}
@@ -502,8 +511,12 @@ class Popup extends UI5Element {
502511

503512
get classes() {
504513
return {
505-
root: {},
506-
content: {},
514+
root: {
515+
"ui5-popup-root": true,
516+
},
517+
content: {
518+
"ui5-popup-content": true,
519+
},
507520
};
508521
}
509522
}

packages/main/src/themes/PopupsCommon.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
overflow: hidden;
2121
max-height: 94vh;
2222
max-width: 90vw;
23+
outline: none;
2324
}
2425

2526
@media screen and (-ms-high-contrast: active) {

packages/main/test/pages/Popover.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,4 +505,4 @@
505505
</script>
506506
</body>
507507

508-
</html>
508+
</html>

0 commit comments

Comments
 (0)