@cqa-lib/cqa-ui 1.0.94 → 1.0.95

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1513,7 +1513,13 @@ class DynamicSelectFieldComponent {
1513
1513
  this.searchTextByKey = {};
1514
1514
  this.lastOptionsLength = 0;
1515
1515
  this.loadingMore = false;
1516
+ /**
1517
+ * Guard to ensure load-more is only triggered after the user has scrolled
1518
+ * at least once since opening the panel. Prevents auto-load on open.
1519
+ */
1520
+ this.hasScrolledSinceOpen = false;
1516
1521
  this.onPanelScroll = () => {
1522
+ this.hasScrolledSinceOpen = true;
1517
1523
  if (!this.config?.hasMore || this.loadingMore)
1518
1524
  return;
1519
1525
  const el = this.panelScrollEl;
@@ -1557,6 +1563,17 @@ class DynamicSelectFieldComponent {
1557
1563
  this.loadingMore = false;
1558
1564
  }
1559
1565
  this.lastOptionsLength = len;
1566
+ // If consumer indicates no more results, clear loading state and any observers
1567
+ if (!this.config?.hasMore) {
1568
+ this.loadingMore = false;
1569
+ if (this.loadMoreObserver) {
1570
+ try {
1571
+ this.loadMoreObserver.disconnect();
1572
+ }
1573
+ catch { }
1574
+ this.loadMoreObserver = undefined;
1575
+ }
1576
+ }
1560
1577
  // If panel is open and hasMore is true, ensure the sentinel is being observed.
1561
1578
  if (this.selectRef?.panelOpen && this.config?.hasMore) {
1562
1579
  setTimeout(() => this.setupLoadMoreObserver(), 0);
@@ -1722,6 +1739,8 @@ class DynamicSelectFieldComponent {
1722
1739
  if ((this.config?.options || []).length > 0) {
1723
1740
  this.loadingMore = false;
1724
1741
  }
1742
+ // Ensure we only trigger load-more after a real user scroll
1743
+ this.hasScrolledSinceOpen = false;
1725
1744
  }
1726
1745
  if (!opened) {
1727
1746
  // Reset search text on close so the next open shows full list
@@ -1760,8 +1779,8 @@ class DynamicSelectFieldComponent {
1760
1779
  input?.focus();
1761
1780
  }, 0);
1762
1781
  }
1763
- // In serverSearch mode, if no options yet, trigger initial fetch
1764
- if (this.config?.serverSearch) {
1782
+ // Optional: only trigger initial fetch on open when explicitly requested.
1783
+ if (this.config?.serverSearch && this.toBoolean(this.config?.initialFetchOnOpen)) {
1765
1784
  const key = this.config.key;
1766
1785
  const q = this.searchTextByKey[key] || '';
1767
1786
  try {
@@ -1953,7 +1972,7 @@ class DynamicSelectFieldComponent {
1953
1972
  for (const entry of entries) {
1954
1973
  if (entry.isIntersecting) {
1955
1974
  // Request more only if not currently loading and hasMore still true
1956
- if (!this.loadingMore && this.config?.hasMore) {
1975
+ if (this.hasScrolledSinceOpen && !this.loadingMore && this.config?.hasMore) {
1957
1976
  this.loadingMore = true;
1958
1977
  const key = this.config?.key || '';
1959
1978
  const q = this.searchTextByKey[key] || '';