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-popover): fix finding opener when popover is not in the DOM #10338

Merged
merged 2 commits into from
Dec 9, 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
8 changes: 4 additions & 4 deletions packages/main/src/Popover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,13 +301,13 @@ class Popover extends Popup {
return opener;
}

const rootNode = this.getRootNode();
let rootNode = this.getRootNode();

if (!(rootNode instanceof ShadowRoot || rootNode instanceof Document)) {
return;
if (rootNode === this) {
rootNode = document;
}

let openerHTMLElement = rootNode.getElementById(opener);
let openerHTMLElement = (rootNode as Document | ShadowRoot).getElementById(opener);

if (rootNode instanceof ShadowRoot && !openerHTMLElement) {
openerHTMLElement = document.getElementById(opener);
Expand Down
8 changes: 4 additions & 4 deletions packages/main/test/pages/PopoverInitiallyOpen.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">

<title>Dialog</title>
<title>Popover Initially Open</title>

<script data-ui5-config type="application/json">
{
Expand All @@ -16,14 +16,14 @@
<script>
function init() {
const popover = document.createElement("ui5-popover");
popover.id = "dialogOpen";
popover.headerText = "Dialog Header";
popover.id = "popoverOpen";
popover.headerText = "Popover Header";

popover.open = true;
popover.opener = "btn1";

const content = document.createElement("div");
content.innerHTML = "<button>button</button>";
content.innerHTML = "<button id='popoverBtn'>button</button>";
popover.appendChild(content);

document.body.appendChild(popover);
Expand Down
14 changes: 14 additions & 0 deletions packages/main/test/specs/Popover.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,20 @@ describe("Opener", () => {
});
});

describe("Initially opened", () => {
before(async () => {
await browser.url(`test/pages/PopoverInitiallyOpen.html`);
});

it("test :popover-open selector", async () => {
assert.ok(await browser.$("#popoverOpen").matches(":popover-open"), "popover is opened correctly");
});

it("test initial focus", async () => {
assert.ok(await browser.$("#popoverBtn").matches(":focus"), "initial focus is correct");
});
});

describe("Acc", () => {
before(async () => {
await browser.url(`test/pages/Popover.html`);
Expand Down
Loading