Skip to content

Commit b36e54e

Browse files
authored
fix(ui5-list): fix JS error on focusin (#2720)
Fixe a JS error that used to thrown upon "focusin" when non-existing DOM elements have been accessed. Those DOM elements are not rendered when there are no list items, which is the example in the referenced issue. FIXES: #2717
1 parent 014c985 commit b36e54e

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

packages/main/src/List.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -586,12 +586,14 @@ class List extends UI5Element {
586586

587587
isForwardElement(node) {
588588
const nodeId = node.id;
589+
const afterElement = this.getAfterElement();
590+
const beforeElement = this.getBeforeElement();
589591

590-
if (this._id === nodeId || this.getBeforeElement().id === nodeId) {
592+
if (this._id === nodeId || (beforeElement && beforeElement.id === nodeId)) {
591593
return true;
592594
}
593595

594-
return this.getAfterElement().id === nodeId;
596+
return afterElement && afterElement.id === nodeId;
595597
}
596598

597599
onItemFocused(event) {

packages/main/test/pages/List_test_page.html

+19-1
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,20 @@ <h2 id="testHeader">Test aria</h2>
174174
</ui5-list>
175175

176176
<ui5-input value="0" id="customListItemEvents"></ui5-input>
177+
<br />
178+
<br />
179+
<ui5-button id="btnOpenPopup">Open popup with List</ui5-button>
180+
<ui5-responsive-popover id="popup" placement-type="Bottom" style="width: 300px;height: 18rem;">
181+
<ui5-list>
182+
<div slot="header">
183+
<ui5-button id="btnInHeader" icon="refresh" />
184+
</div>
185+
</ui5-list>
186+
187+
<ui5-list style="height: 15rem" infinite-scroll no-data-text="No data">
188+
<ui5-li>Test</ui5-li>
189+
</ui5-list>
190+
</ui5-responsive-popover>
177191

178192
<script>
179193
'use strict';
@@ -249,9 +263,13 @@ <h2 id="testHeader">Test aria</h2>
249263
customListItemEventsValue = 0,
250264
customListItemEventsInput = document.getElementById("customListItemEvents");
251265

252-
ui5List.addEventListener("ui5-item-click", (event) => {
266+
ui5List.addEventListener("ui5-item-click", function(event) {
253267
customListItemEventsInput.value = ++customListItemEventsValue;
254268
});
269+
270+
btnOpenPopup.addEventListener("click", function() {
271+
popup.openBy(btnOpenPopup);
272+
});
255273
</script>
256274
</body>
257275
</html>

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

+8
Original file line numberDiff line numberDiff line change
@@ -303,4 +303,12 @@ describe("List Tests", () => {
303303

304304
assert.strictEqual(input.getProperty("value"), "0", "item-click event is not fired when the button is pressed.");
305305
});
306+
307+
it("Popover with List opens without errors", () => {
308+
const btnPopupOpener = $("#btnOpenPopup");
309+
const btnInListHeader = $("#btnInHeader");
310+
311+
btnPopupOpener.click();
312+
assert.strictEqual(btnInListHeader.isFocused(), true, "The List header btn is focused.");
313+
});
306314
});

0 commit comments

Comments
 (0)