Skip to content

Commit 583f5f0

Browse files
authored
fix(ui5-li-custom): keyboard handling improvement (#2870)
Key up and key down events should be prevented when the focus is on child element of the ui5-li-custom. Exception is made for the case where Tab key is pressed so the logic about item navigation from the extended class to be executed. Fixes: #2849
1 parent 76ef62c commit 583f5f0

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

packages/main/src/CustomListItem.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import ListItem from "./ListItem.js";
22
import CustomListItemTemplate from "./generated/templates/CustomListItemTemplate.lit.js";
3+
import { isTabNext, isTabPrevious } from "@ui5/webcomponents-base/dist/Keys.js";
34

45
// Styles
56
import customListItemCss from "./generated/themes/CustomListItem.css.js";
@@ -55,15 +56,19 @@ class CustomListItem extends ListItem {
5556
}
5657

5758
_onkeydown(event) {
58-
if (!this.focused) {
59+
const isTab = isTabNext(event) || isTabPrevious(event);
60+
61+
if (!isTab && !this.focused) {
5962
return;
6063
}
6164

6265
super._onkeydown(event);
6366
}
6467

6568
_onkeyup(event) {
66-
if (!this.focused) {
69+
const isTab = isTabNext(event) || isTabPrevious(event);
70+
71+
if (!isTab && !this.focused) {
6772
return;
6873
}
6974

packages/main/test/pages/List_test_page.html

+1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
<ui5-radiobutton text="Option C" disabled="disabled"></ui5-radiobutton>
9898
</ui5-li-custom>
9999
</ui5-list>
100+
<ui5-button id="randomBtn">Random button</ui5-button>
100101

101102
<ui5-list id="no-data-list" header-text="API: noDataText" separators="None" no-data-text="No Data Available"></ui5-list>
102103

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

+6
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ describe("List Tests", () => {
185185
const itemBtn = $("ui5-button.itemBtn");
186186
const itemLink = $("ui5-link.itemLink");
187187
const itemRadioBtn = $("ui5-radiobutton.itemRadio");
188+
const randomBtn = $("#randomBtn");
188189

189190
headerBtn.click();
190191
assert.strictEqual(headerBtn.isFocused(), true, "header btn is focused");
@@ -205,6 +206,11 @@ describe("List Tests", () => {
205206
// and go to the "Option B" radio button
206207
itemLink.keys("Tab");
207208
assert.strictEqual(itemRadioBtn.isFocused(), true, "the last tabbable element (radio) is focused");
209+
210+
// act: TAB from the "Option B" radio button - the focus should leave the ui5-list
211+
// and Random button should be focused
212+
itemLink.keys("Tab");
213+
assert.strictEqual(randomBtn.isFocused(), true, "element outside of the list is focused");
208214
});
209215

210216
it("does not focus next / prev item when right / left arrow is pressed", () => {

0 commit comments

Comments
 (0)