Skip to content

Commit 0e0344c

Browse files
authored
fix(ui5-popover): add header and footer to focus trapping (#1298)
1 parent b5e1337 commit 0e0344c

File tree

3 files changed

+70
-6
lines changed

3 files changed

+70
-6
lines changed

packages/main/src/Popover.hbs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<div class="ui5-popover-root" role="dialog" aria-modal="true" aria-labelledby="ui5-popover-header" style={{styles.root}}>
22

3+
<span class="first-fe" tabindex="0" @focusin={{forwardToLast}}></span>
4+
35
<span class="ui5-popover-arr" style="{{styles.arrow}}"></span>
46

57
{{#if _displayHeader}}
@@ -12,13 +14,11 @@
1214
{{/if}}
1315
{{/if}}
1416

15-
<span class="first-fe" tabindex="0" @focusin={{forwardToLast}}></span>
1617

1718
<div class="ui5-popover-content" style={{styles.content}}>
1819
<slot></slot>
1920
</div>
2021

21-
<span class="last-fe" tabindex="0" @focusin={{forwardToFirst}}></span>
2222

2323
{{#if _displayFooter}}
2424
{{#if footer.length }}
@@ -28,4 +28,6 @@
2828
{{/if}}
2929
{{/if}}
3030

31+
<span class="last-fe" tabindex="0" @focusin={{forwardToFirst}}></span>
32+
3133
</div>

packages/main/test/pages/Popover.html

+6-4
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@
6161
<ui5-button id="btn">Click me !</ui5-button>
6262

6363
<ui5-popover header-text="My Heading" id="pop" style="width: 300px" placement-type="Top">
64-
<!-- <div slot="header">
65-
Hello World
66-
</div> -->
64+
<div slot="header">
65+
<ui5-button id="first-focusable">I am in the header</ui5-button>
66+
</div>
6767

6868
<ui5-list>
6969
<ui5-li>Hello</ui5-li>
@@ -77,6 +77,8 @@
7777
<ui5-button id='popbtn'>Open Popover</ui5-button>
7878

7979
<ui5-popover placement-type="Bottom" no-arrow id='danger'>
80+
81+
8082
<ui5-list>
8183
<ui5-li>Hello</ui5-li>
8284
<ui5-li>World</ui5-li>
@@ -111,7 +113,7 @@
111113
<!-- <ui5-datepicker></ui5-datepicker> -->
112114

113115
<div slot="footer">
114-
Hello World Footer
116+
<ui5-button>I am in the footer</ui5-button>
115117
</div>
116118
</ui5-popover>
117119

packages/main/test/specs/Popover.spec.js

+60
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,64 @@ describe("Popover general interaction", () => {
119119

120120
assert.ok(focusedButton.getProperty("focused"), "The button is focused.");
121121
});
122+
123+
it("tests focus trapping using TAB", () => {
124+
browser.url("http://localhost:8080/test-resources/pages/Popover.html");
125+
126+
const btn = $("#btn");
127+
const ff = $("#first-focusable");
128+
129+
btn.click();
130+
131+
assert.ok(ff.getProperty("focused"), "The first focusable element is focused.");
132+
133+
// list
134+
browser.keys("Tab");
135+
136+
assert.ok(!ff.getProperty("focused"), "The first focusable element is focused.");
137+
138+
// button
139+
browser.keys("Tab");
140+
141+
assert.ok(!ff.getProperty("focused"), "The first focusable element is focused.");
142+
143+
// select
144+
browser.keys("Tab");
145+
146+
// footer button
147+
browser.keys("Tab");
148+
149+
// goes to first focusable again
150+
browser.keys("Tab");
151+
152+
assert.ok(ff.getProperty("focused"), "The first focusable element is focused.");
153+
});
154+
155+
it("tests focus trapping using SHIFT TAB", () => {
156+
browser.url("http://localhost:8080/test-resources/pages/Popover.html");
157+
158+
const btn = $("#btn");
159+
const ff = $("#first-focusable");
160+
161+
btn.click();
162+
163+
assert.ok(ff.getProperty("focused"), "The first focusable element is focused.");
164+
165+
// footer button
166+
browser.keys(["Shift", "Tab"]);
167+
168+
// select
169+
browser.keys(["Shift", "Tab"]);
170+
171+
// button
172+
browser.keys(["Shift", "Tab"]);
173+
174+
// list
175+
browser.keys(["Shift", "Tab"]);
176+
177+
// header button
178+
browser.keys(["Shift", "Tab"]);
179+
180+
assert.ok(ff.getProperty("focused"), "The first focusable element is focused.");
181+
});
122182
});

0 commit comments

Comments
 (0)