Skip to content

Commit bd9299e

Browse files
authored
fix(ui5-form-item): update host element display (#12208)
The isElementHidden method called internally by getFirstFocusableElement returns true on Safari for the ui5-form-item, considering the element as hidden, skipping the traverse of its children. This happens, because el.offsetHight and offsetWidth for the host custom element (ui5-form-item custom element in the specific issue) are 0 on Safari. This probably happens for other components - Safari's layout engine doesn't always calculate dimensions correctly for the host element when content is in shadow DOM. Solution - add display to the host element. Fixes: #12201
1 parent 1294c4e commit bd9299e

File tree

2 files changed

+75
-4
lines changed

2 files changed

+75
-4
lines changed

packages/base/cypress/specs/util/FocusableElements.cy.tsx

Lines changed: 70 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
import { getFirstFocusableElement } from "@ui5/webcomponents-base/dist/util/FocusableElements.js";
2+
3+
import Label from "@ui5/webcomponents/dist/Label.js";
4+
import Text from "@ui5/webcomponents/dist/Text.js";
5+
import Button from "@ui5/webcomponents/dist/Button.js";
6+
import Dialog from "@ui5/webcomponents/dist/Dialog.js";
7+
import Input from "@ui5/webcomponents/dist/Input.js";
8+
import Form from "@ui5/webcomponents/dist/Form.js";
9+
import FormItem from "@ui5/webcomponents/dist/FormItem.js";
210
import SideNavigation from "@ui5/webcomponents-fiori/dist/SideNavigation.js";
311
import SideNavigationItem from "@ui5/webcomponents-fiori/dist/SideNavigationItem.js";
412
import SideNavigationSubItem from "@ui5/webcomponents-fiori/dist/SideNavigationSubItem.js";
5-
import Button from "@ui5/webcomponents/dist/Button.js";
6-
import Input from "@ui5/webcomponents/dist/Input.js";
713

814
describe("FocusableElements", () => {
915
it("Tests first focusable element", () => {
1016
cy.mount(
1117
<>
1218
<div id="container">
13-
<Input tabindex="-1"></Input>
19+
<Input tabindex={-1}></Input>
1420
<br/>
1521
<SideNavigation>
1622
<SideNavigationItem
@@ -38,11 +44,71 @@ describe("FocusableElements", () => {
3844
.should("have.attr", "tabindex", "0");
3945

4046
cy.get("#container").then( async ($container) => {
41-
const firstFocusable = await getFirstFocusableElement($container.get(0));
47+
const firstFocusable = await getFirstFocusableElement($container.get(0)!);
4248
await firstFocusable?.focus();
4349
});
4450

4551
cy.get("#subItem1")
4652
.should("have.focus");
4753
});
54+
55+
it("Tests first focusable element inside Dialog with focusable content", () => {
56+
cy.mount(
57+
<Dialog id="dialog" headerText="Dialog" open={true}>
58+
<Form headerText="Address">
59+
<FormItem>
60+
<Label slot="labelContent">Name:</Label>
61+
<Input id="nameInp"/>
62+
</FormItem>
63+
64+
<FormItem>
65+
<Label slot="labelContent">ZIP Code/City:</Label>
66+
<Input value="411"/>
67+
</FormItem>
68+
</Form>
69+
70+
<div slot="footer" class="dialogFooter">
71+
<Button design="Emphasized">Close</Button>
72+
</div>
73+
</Dialog>
74+
);
75+
76+
cy.get("#dialog").then( async ($container) => {
77+
const firstFocusable = await getFirstFocusableElement($container.get(0)!);
78+
await firstFocusable?.focus();
79+
});
80+
81+
cy.get("#nameInp")
82+
.should("have.focus");
83+
});
84+
85+
it("Tests first focusable element inside Dialog with focusable footer", () => {
86+
cy.mount(
87+
<Dialog id="dialog" headerText="Dialog" open={true}>
88+
<Form headerText="Address">
89+
<FormItem>
90+
<Label slot="labelContent">Name:</Label>
91+
<Text>Richard</Text>
92+
</FormItem>
93+
94+
<FormItem>
95+
<Label slot="labelContent">ZIP Code/City:</Label>
96+
<Text>New York</Text>
97+
</FormItem>
98+
</Form>
99+
100+
<div slot="footer" class="dialogFooter">
101+
<Button id="btnClose" design="Emphasized">Close</Button>
102+
</div>
103+
</Dialog>
104+
);
105+
106+
cy.get("#dialog").then( async ($container) => {
107+
const firstFocusable = await getFirstFocusableElement($container.get(0)!);
108+
await firstFocusable?.focus();
109+
});
110+
111+
cy.get("#btnClose")
112+
.should("have.focus");
113+
});
48114
});

packages/main/src/themes/FormItem.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
:host(:not([hidden])) {
2+
display: block;
3+
width: 100%;
4+
}
5+
16
:host([column-span="1"]) {
27
grid-column: span 1;
38
}

0 commit comments

Comments
 (0)