Skip to content

Commit 3f66c06

Browse files
authored
fix(ui5-li-custom): prevent firing of events (#2462)
1 parent 13ff13e commit 3f66c06

File tree

3 files changed

+62
-7
lines changed

3 files changed

+62
-7
lines changed

packages/main/src/CustomListItem.js

+16
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,22 @@ class CustomListItem extends ListItem {
5353
return [ListItem.styles, customListItemCss];
5454
}
5555

56+
_onkeydown(event) {
57+
if (!this.focused) {
58+
return;
59+
}
60+
61+
super._onkeydown(event);
62+
}
63+
64+
_onkeyup(event) {
65+
if (!this.focused) {
66+
return;
67+
}
68+
69+
super._onkeyup(event);
70+
}
71+
5672
get classes() {
5773
const result = super.classes;
5874
result.main["ui5-custom-li-root"] = true;

packages/main/test/pages/List_test_page.html

+29
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,26 @@ <h2 id="testHeader">Test aria</h2>
154154
<ui5-li>HP Monitor 24</ui5-li>
155155
</ui5-list>
156156
<ui5-button id="changeEmptyItem">Change empty item text</ui5-button>
157+
<br>
158+
<ui5-title>Events within ui5-li-custom</ui5-title>
159+
<br>
160+
161+
<ui5-list id="customList" separators="Inner">
162+
<ui5-li-custom>
163+
<ui5-button id="liBtn1" design="Transparent">List Button 1</ui5-button>
164+
<br />
165+
</ui5-li-custom>
166+
<ui5-li-custom>
167+
<ui5-button design="Transparent">List Button 2</ui5-button>
168+
<br />
169+
</ui5-li-custom>
170+
<ui5-li-custom>
171+
<ui5-button design="Transparent">List Button 2</ui5-button>
172+
<br />
173+
</ui5-li-custom>
174+
</ui5-list>
175+
176+
<ui5-input value="0" id="customListItemEvents"></ui5-input>
157177

158178
<script>
159179
'use strict';
@@ -223,6 +243,15 @@ <h2 id="testHeader">Test aria</h2>
223243
detailListItem.addEventListener("ui5-detailClick", function(e) {
224244
detailPressCounter.innerHTML = parseInt(detailPressCounter.innerHTML) + 1;
225245
});
246+
247+
var ui5List = document.getElementById("customList"),
248+
liBtn1 = document.getElementById("liBtn1"),
249+
customListItemEventsValue = 0,
250+
customListItemEventsInput = document.getElementById("customListItemEvents");
251+
252+
ui5List.addEventListener("ui5-item-click", (event) => {
253+
customListItemEventsInput.value = ++customListItemEventsValue;
254+
});
226255
</script>
227256
</body>
228257
</html>

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

+17-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ describe("List Tests", () => {
88

99
it("List is rendered", () => {
1010
const list = browser.$("ui5-list").shadow$(".ui5-list-root");
11-
11+
1212
assert.ok(list, "List is rendered");
1313
});
1414

@@ -79,7 +79,7 @@ describe("List Tests", () => {
7979

8080
return result.length;
8181
});
82-
82+
8383
assert.strictEqual(listItemsLength, 3, "List items are rendered");
8484
});
8585

@@ -246,7 +246,7 @@ describe("List Tests", () => {
246246
const listWithCustomHeader = $("#listWithCustomHeader");
247247
const ulInternalHeader = listWithInternalHeader.shadow$(".ui5-list-ul");
248248
const ulCustomHeader = listWithCustomHeader.shadow$(".ui5-list-ul");
249-
249+
250250
// assert: List with internal header
251251
const listWithInternalHeaderId = listWithInternalHeader.getProperty("_id");
252252
assert.strictEqual(ulInternalHeader.getAttribute("aria-label"),
@@ -286,9 +286,19 @@ describe("List Tests", () => {
286286
});
287287

288288
// assert
289-
assert.strictEqual(emptyItem.getProperty("innerHTML"), NEW_TEXT,
290-
"The value is updated");
291-
assert.strictEqual(assignedNodesAfter, 1,
292-
"The new text is slotted.");
289+
assert.strictEqual(emptyItem.getProperty("innerHTML"), NEW_TEXT, "The value is updated");
290+
assert.strictEqual(assignedNodesAfter, 1, "The new text is slotted.");
291+
});
292+
293+
it("tests events for ui5-li-custom", () => {
294+
const button = $("#liBtn1");
295+
const input = $("#customListItemEvents");
296+
297+
button.click();
298+
299+
browser.keys("Enter");
300+
browser.keys("Space");
301+
302+
assert.strictEqual(input.getProperty("value"), "0", "item-click event is not fired when the button is pressed.");
293303
});
294304
});

0 commit comments

Comments
 (0)