Skip to content

Commit 26de583

Browse files
fix(popups): fix finding initial focus when Tokenizer is placed (#11761)
* fix(popups): fix finding initial focus
1 parent 4dcc57e commit 26de583

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

packages/base/src/util/isElementHidden.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ const isElementHidden = (el: HTMLElement) => {
33
return false;
44
}
55

6-
return (el.offsetWidth <= 0 && el.offsetHeight <= 0) || (window.getComputedStyle(el).visibility === "hidden");
6+
const computedStyle = window.getComputedStyle(el);
7+
8+
return (computedStyle.display !== "contents" && (el.offsetWidth <= 0 && el.offsetHeight <= 0)) || (computedStyle.visibility === "hidden");
79
};
810

911
export default isElementHidden;

packages/main/cypress/specs/Dialog.cy.tsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import Dialog from "../../src/Dialog.js";
33
import Label from "../../src/Label.js";
44
import Toolbar from "../../src/Toolbar.js";
55
import ToolbarButton from "../../src/ToolbarButton.js";
6+
import Tokenizer from "../../src/Tokenizer.js";
7+
import Token from "../../src/Token.js";
68

79
describe("Keyboard", () => {
810
it("TAB navigation", () => {
@@ -82,6 +84,35 @@ describe("Keyboard", () => {
8284
});
8385
});
8486

87+
describe("Initial Focus", () => {
88+
it("Tokenizer focusing", () => {
89+
cy.mount(
90+
<>
91+
<Dialog id="dialogId" headerText="Tokens">
92+
<Tokenizer id="tokenizer">
93+
<Token text="Token 1" id="token1"/>
94+
<Token text="Token 2" id="token2"/>
95+
</Tokenizer>
96+
</Dialog>
97+
</>
98+
);
99+
100+
cy.get("#token1")
101+
.shadow()
102+
.find(".ui5-token--wrapper")
103+
.should("have.attr", "tabindex", "0");
104+
105+
cy.get("#dialogId")
106+
.invoke("prop", "open", true);
107+
108+
cy.get("#token1")
109+
.should("be.visible");
110+
111+
cy.get("#token1")
112+
.should("be.focused");
113+
});
114+
});
115+
85116
describe("Accessibility", () => {
86117
it("Dialog accessibleDescriptionRef Tests", () => {
87118
cy.mount(

packages/main/test/pages/Dialog.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,15 @@
680680
</ui5-dialog>
681681
<br>
682682
<br>
683+
<ui5-button onclick="dialogWithTokenizer.open = true;">Open Dialog With Tokenizer</ui5-button>
684+
<ui5-dialog id="dialogWithTokenizer" header-text="Tokens">
685+
<ui5-tokenizer id="tokenizer">
686+
<ui5-token text="Token 1"></ui5-token>
687+
<ui5-token text="Token 2"></ui5-token>
688+
</ui5-tokenizer>
689+
</ui5-dialog>
690+
<br>
691+
<br>
683692
<div>
684693
<ui5-title level="H3">Open Dialog from list</ui5-title>
685694
<ui5-list id="listContainerId" selection-mode="Single">

0 commit comments

Comments
 (0)