Skip to content

Commit 682a25c

Browse files
authored
fix(ui5-li): fix title update when initially empty (#2362)
When the textContent is an empty string initially, the following element is not rendered <span part="title" class="ui5-li-title"><slot></slot></span> Later when we update the textContent, it is not displayed as it relies on the slotting, but the slot element is not there. The issue has been found in a specific Select use case, referenced below. I considered making a ui5-select-list-item and make that change in a separate template, but I can't find side effects or visual degradations. FIXES #2342
1 parent ff67141 commit 682a25c

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

packages/main/src/StandardListItem.hbs

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
{{#*inline "listItemContent"}}
44
<div class="ui5-li-title-wrapper">
5-
{{#if textContent.length}}
6-
<span part="title" class="ui5-li-title"><slot></slot></span>
7-
{{/if}}
5+
<span part="title" class="ui5-li-title"><slot></slot></span>
86
{{#if description}}
97
<span part="description" class="ui5-li-desc">{{description}}</span>
108
{{/if}}

packages/main/test/pages/List_test_page.html

+11
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,13 @@ <h2 id="testHeader">Test aria</h2>
148148
<ui5-li >item</ui5-li>
149149
</ui5-list>
150150

151+
<ui5-list id="listWithEmptyItem">
152+
<ui5-li id="emptyItem"></ui5-li>
153+
<ui5-li>IPhone 3</ui5-li>
154+
<ui5-li>HP Monitor 24</ui5-li>
155+
</ui5-list>
156+
<ui5-button id="changeEmptyItem">Change empty item text</ui5-button>
157+
151158
<script>
152159
'use strict';
153160

@@ -199,6 +206,10 @@ <h2 id="testHeader">Test aria</h2>
199206
scrollableContiner.scroll(0, scrollableContiner.scrollHeight);
200207
});
201208

209+
changeEmptyItem.addEventListener("click", function(e) {
210+
emptyItem.textContent = "updated";
211+
});
212+
202213
var loadMoreCounter = 0;
203214
infiniteScrollEx.addEventListener("ui5-loadMore", function(e) {
204215
for(var i = 0; i < 3; i++) {

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

+28
Original file line numberDiff line numberDiff line change
@@ -263,4 +263,32 @@ describe("List Tests", () => {
263263
assert.strictEqual(ulCustomHeader.getAttribute("aria-labelledby"),
264264
null, "aria-labelledby is not present");
265265
});
266+
267+
it("tests title is updated, when initially empty", () => {
268+
const btnChangeEmptyItem = $("#changeEmptyItem");
269+
const emptyItem = $("#emptyItem");
270+
const NEW_TEXT = "updated";
271+
const assignedNodesBefore = browser.execute(() => {
272+
return document.getElementById("emptyItem").shadowRoot.querySelector("slot").assignedNodes().length;
273+
});
274+
275+
// assert default
276+
assert.strictEqual(emptyItem.getProperty("innerHTML"), "",
277+
"The value is empty string");
278+
assert.strictEqual(assignedNodesBefore, 0,
279+
"No slotted elements as no text is present.");
280+
281+
// act
282+
btnChangeEmptyItem.click(); // update the item textContent
283+
284+
const assignedNodesAfter = browser.execute(() => {
285+
return document.getElementById("emptyItem").shadowRoot.querySelector("slot").assignedNodes().length;
286+
});
287+
288+
// 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.");
293+
});
266294
});

0 commit comments

Comments
 (0)