Skip to content

Commit

Permalink
fix(ui5-li-custom): prevent firing of events (#2462)
Browse files Browse the repository at this point in the history
  • Loading branch information
fifoosid authored Nov 19, 2020
1 parent 13ff13e commit 3f66c06
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 7 deletions.
16 changes: 16 additions & 0 deletions packages/main/src/CustomListItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,22 @@ class CustomListItem extends ListItem {
return [ListItem.styles, customListItemCss];
}

_onkeydown(event) {
if (!this.focused) {
return;
}

super._onkeydown(event);
}

_onkeyup(event) {
if (!this.focused) {
return;
}

super._onkeyup(event);
}

get classes() {
const result = super.classes;
result.main["ui5-custom-li-root"] = true;
Expand Down
29 changes: 29 additions & 0 deletions packages/main/test/pages/List_test_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,26 @@ <h2 id="testHeader">Test aria</h2>
<ui5-li>HP Monitor 24</ui5-li>
</ui5-list>
<ui5-button id="changeEmptyItem">Change empty item text</ui5-button>
<br>
<ui5-title>Events within ui5-li-custom</ui5-title>
<br>

<ui5-list id="customList" separators="Inner">
<ui5-li-custom>
<ui5-button id="liBtn1" design="Transparent">List Button 1</ui5-button>
<br />
</ui5-li-custom>
<ui5-li-custom>
<ui5-button design="Transparent">List Button 2</ui5-button>
<br />
</ui5-li-custom>
<ui5-li-custom>
<ui5-button design="Transparent">List Button 2</ui5-button>
<br />
</ui5-li-custom>
</ui5-list>

<ui5-input value="0" id="customListItemEvents"></ui5-input>

<script>
'use strict';
Expand Down Expand Up @@ -223,6 +243,15 @@ <h2 id="testHeader">Test aria</h2>
detailListItem.addEventListener("ui5-detailClick", function(e) {
detailPressCounter.innerHTML = parseInt(detailPressCounter.innerHTML) + 1;
});

var ui5List = document.getElementById("customList"),
liBtn1 = document.getElementById("liBtn1"),
customListItemEventsValue = 0,
customListItemEventsInput = document.getElementById("customListItemEvents");

ui5List.addEventListener("ui5-item-click", (event) => {
customListItemEventsInput.value = ++customListItemEventsValue;
});
</script>
</body>
</html>
24 changes: 17 additions & 7 deletions packages/main/test/specs/List.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe("List Tests", () => {

it("List is rendered", () => {
const list = browser.$("ui5-list").shadow$(".ui5-list-root");

assert.ok(list, "List is rendered");
});

Expand Down Expand Up @@ -79,7 +79,7 @@ describe("List Tests", () => {

return result.length;
});

assert.strictEqual(listItemsLength, 3, "List items are rendered");
});

Expand Down Expand Up @@ -246,7 +246,7 @@ describe("List Tests", () => {
const listWithCustomHeader = $("#listWithCustomHeader");
const ulInternalHeader = listWithInternalHeader.shadow$(".ui5-list-ul");
const ulCustomHeader = listWithCustomHeader.shadow$(".ui5-list-ul");

// assert: List with internal header
const listWithInternalHeaderId = listWithInternalHeader.getProperty("_id");
assert.strictEqual(ulInternalHeader.getAttribute("aria-label"),
Expand Down Expand Up @@ -286,9 +286,19 @@ describe("List Tests", () => {
});

// assert
assert.strictEqual(emptyItem.getProperty("innerHTML"), NEW_TEXT,
"The value is updated");
assert.strictEqual(assignedNodesAfter, 1,
"The new text is slotted.");
assert.strictEqual(emptyItem.getProperty("innerHTML"), NEW_TEXT, "The value is updated");
assert.strictEqual(assignedNodesAfter, 1, "The new text is slotted.");
});

it("tests events for ui5-li-custom", () => {
const button = $("#liBtn1");
const input = $("#customListItemEvents");

button.click();

browser.keys("Enter");
browser.keys("Space");

assert.strictEqual(input.getProperty("value"), "0", "item-click event is not fired when the button is pressed.");
});
});

0 comments on commit 3f66c06

Please sign in to comment.