Skip to content

Commit ef52f2b

Browse files
authored
fix(ui5-list): prevent load-more on initial intersection (#3105)
This is a change already merged in release-0.29, because of a tight deadline, set by stakeholders. Now we ensure that the issue is fixed in the future versions. The commit in the release-0.29 branch is the following: af2070f And the change fixes the case when the List does not actually overflow, the bottom most part of the List is visible and the IntersectionObserver detects that the bottom of the List is reached. What happens in the apps is that the List fires "load-more" just before the items that the app wants to show initially are actually rendered, which results in additional loading, not due to user scroll.
1 parent 48a002a commit ef52f2b

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

packages/main/src/List.js

+15-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import litRender from "@ui5/webcomponents-base/dist/renderer/LitRenderer.js";
33
import ResizeHandler from "@ui5/webcomponents-base/dist/delegate/ResizeHandler.js";
44
import ItemNavigation from "@ui5/webcomponents-base/dist/delegate/ItemNavigation.js";
55
import { isIE } from "@ui5/webcomponents-base/dist/Device.js";
6+
import { renderFinished } from "@ui5/webcomponents-base/dist/Render.js";
67
import { getLastTabbableElement } from "@ui5/webcomponents-base/dist/util/TabbableElements.js";
78
import { isTabNext, isSpace, isEnter } from "@ui5/webcomponents-base/dist/Keys.js";
89
import NavigationMode from "@ui5/webcomponents-base/dist/types/NavigationMode.js";
@@ -424,6 +425,10 @@ class List extends UI5Element {
424425

425426
this._handleResize = this.checkListInViewport.bind(this);
426427
this.i18nBundle = getI18nBundle("@ui5/webcomponents");
428+
429+
// Indicates the List bottom most part has been detected by the IntersectionObserver
430+
// for the first time.
431+
this.initialIntersection = true;
427432
}
428433

429434
onExitDOM() {
@@ -551,8 +556,9 @@ class List extends UI5Element {
551556
this._previouslySelectedItem = null;
552557
}
553558

554-
observeListEnd() {
559+
async observeListEnd() {
555560
if (!this.listEndObserved) {
561+
await renderFinished();
556562
this.getIntersectionObserver().observe(this.listEndDOM);
557563
this.listEndObserved = true;
558564
}
@@ -567,9 +573,15 @@ class List extends UI5Element {
567573
}
568574

569575
onInteresection(entries) {
570-
if (entries.some(entry => entry.isIntersecting)) {
571-
debounce(this.loadMore.bind(this), INFINITE_SCROLL_DEBOUNCE_RATE);
576+
if (this.initialIntersection) {
577+
this.initialIntersection = false;
578+
return;
572579
}
580+
entries.forEach(entry => {
581+
if (entry.isIntersecting) {
582+
debounce(this.loadMore.bind(this), INFINITE_SCROLL_DEBOUNCE_RATE);
583+
}
584+
});
573585
}
574586

575587
/*

packages/main/test/pages/List_test_page.html

+22
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,20 @@
2626
<ui5-li id="lastItem">Last Item</ui5-li>
2727
</ui5-list>
2828
<input id="loadMoreResult" value="0"/>
29+
<br><br><br>
30+
31+
<ui5-title>List growing="Scroll" items don't overflow initially</ui5-title>
32+
33+
<ui5-input id="growingScrollTestCounter" value="0"></ui5-input>
34+
<section style="max-height: 20rem; overflow: auto;">
35+
<ui5-list id="growingScrollTest" growing="Scroll">
36+
<ui5-li-groupheader>New Items</ui5-li-groupheader>
37+
</ui5-list>
38+
</section>
39+
40+
<br><br><br>
41+
42+
2943
<br/>
3044
<ui5-list id="listEvents" mode="SingleSelectEnd">
3145
<ui5-li id="country1">Argentina</ui5-li>
@@ -38,6 +52,7 @@
3852
<ui5-input id="selectionChangeResultField" placeholder="selectionChange result"></ui5-input>
3953
<ui5-input id="selectionChangeResultPreviousItemsParameter" placeholder="selectionChange previousSelection result"></ui5-input>
4054

55+
<br><br><br>
4156
<ui5-list id="listEvents2" mode="MultiSelect">
4257
<ui5-li id="country11">Argentina</ui5-li>
4358
<ui5-li id="country22" selected >Bulgaria</ui5-li>
@@ -48,6 +63,7 @@
4863
<ui5-input id="itemPressSelectedResultField2" placeholder="itemPress selected result"></ui5-input>
4964
<ui5-input id="selectionChangeResultField2" placeholder="selectionChange result"></ui5-input>
5065

66+
<br><br><br>
5167
<ui5-list id="list1" header-text="API: GroupHeaderListItem">
5268
<ui5-li-groupheader>New Items</ui5-li-groupheader>
5369
<ui5-li image="./img/HT-1000.jpg" >Laptop HP</ui5-li>
@@ -277,6 +293,12 @@ <h2 id="testHeader">Test aria</h2>
277293
btnOpenPopup.addEventListener("click", function() {
278294
popup.openBy(btnOpenPopup);
279295
});
296+
297+
298+
var groiwngScrollTestCounter = 0;
299+
growingScrollTest.addEventListener("ui5-loadMore", function(e) {
300+
growingScrollTestCounter.value= ++groiwngScrollTestCounter;
301+
});
280302
</script>
281303
</body>
282304
</html>

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

+5
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,11 @@ describe("List Tests", () => {
230230
assert.ok(firstListItem.isFocused(), "First item remains focussed");
231231
});
232232

233+
it("tests 'loadMore' event not fired initially when the list did not overflow", () => {
234+
const loadMoreResult = $("#growingScrollTestCounter");
235+
assert.strictEqual(loadMoreResult.getAttribute("value"), "0", "The event loadMore has not been fired.");
236+
});
237+
233238
it("tests 'loadMore' event fired upon infinite scroll", () => {
234239
const btn = $("#btnTrigger");
235240
const loadMoreResult = $("#loadMoreResult");

0 commit comments

Comments
 (0)