Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ui5-popup): remove popup from the tab chain #8955

Merged
merged 7 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/main/src/Popup.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
style="{{styles.root}}"
class="{{classes.root}}"
role="{{_role}}"
tabindex="-1"
aria-modal="{{_ariaModal}}"
aria-label="{{_ariaLabel}}"
aria-labelledby="{{_ariaLabelledBy}}"
Expand Down
14 changes: 2 additions & 12 deletions packages/main/src/Popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import litRender from "@ui5/webcomponents-base/dist/renderer/LitRenderer.js";
import UI5Element from "@ui5/webcomponents-base/dist/UI5Element.js";
import {
isChrome,
isSafari,
isDesktop,
isPhone,
} from "@ui5/webcomponents-base/dist/Device.js";
Expand Down Expand Up @@ -249,6 +248,8 @@ abstract class Popup extends UI5Element {
if (isDesktop()) {
this.setAttribute("desktop", "");
}

this.tabIndex = -1;
}

onExitDOM() {
Expand Down Expand Up @@ -390,10 +391,6 @@ abstract class Popup extends UI5Element {
}

_onmousedown(e: MouseEvent) {
if (!isSafari()) { // Remove when adopting native dialog
this._root.removeAttribute("tabindex");
}

if (this.shadowRoot!.contains(e.target as HTMLElement)) {
this._shouldFocusRoot = true;
} else {
Expand All @@ -402,10 +399,6 @@ abstract class Popup extends UI5Element {
}

_onmouseup() {
if (!isSafari()) { // Remove when adopting native dialog
this._root.tabIndex = -1;
}

if (this._shouldFocusRoot) {
if (isChrome()) {
this._root.focus();
Expand Down Expand Up @@ -476,9 +469,6 @@ abstract class Popup extends UI5Element {
element = element || await getFirstFocusableElement(this) || this._root; // in case of no focusable content focus the root

if (element) {
if (element === this._root) {
element.tabIndex = -1;
}
element.focus();
}
}
Expand Down
19 changes: 16 additions & 3 deletions packages/main/test/pages/Popover.html
Original file line number Diff line number Diff line change
Expand Up @@ -487,9 +487,21 @@ <h2>Horizontal Align</h2>
<div>Content</div>
<div slot="footer">Footer</div>
</ui5-popover>
<br>
<br>

<h2>Inputs with value state</h2>
<div>
<input id="input1"
onfocusin="popoverForInput.open = true"
onfocusout="popoverForInput.open = false">
<ui5-popover opener="input1" id="popoverForInput"
prevent-focus-restore
prevent-initial-focus>
some text
</ui5-popover>
<br>
<input id="input2">
<br>
</div>
<h2>Open and scroll</h2>
<div id="divOpenAndScroll">
<div >
Expand All @@ -499,7 +511,8 @@ <h2>Open and scroll</h2>
</ui5-popover>
</div>
</div>

<br>
<br>
<script>
btn.addEventListener("click", function (event) {
pop.opener = btn;
Expand Down
8 changes: 8 additions & 0 deletions packages/main/test/specs/Popover.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,14 @@ describe("Popover general interaction", () => {

assert.strictEqual(await result.getText(), "No uncaught errors", "There is no error.");
});

it("tests if the popover is a part of the tab chain", async () => {
await browser.$("#input1").scrollIntoView();
await browser.$("#input1").click();
await browser.keys("Tab");

assert.ok(await browser.$("#input2").isFocused(), "next input is focused");
});
});

describe("Acc", () => {
Expand Down