@syncfusion/ej2-lists 26.2.10 → 26.2.14

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.
@@ -1303,6 +1303,7 @@ let ListView = class ListView extends Component {
1303
1303
  }
1304
1304
  break;
1305
1305
  case 'dataSource':
1306
+ this.previousScrollTop = this.element.scrollTop;
1306
1307
  if (this.enableVirtualization) {
1307
1308
  this.virtualizationModule.reRenderUiVirtualization();
1308
1309
  }
@@ -1697,6 +1698,28 @@ let ListView = class ListView extends Component {
1697
1698
  this.virtualizationModule.refreshItemHeight();
1698
1699
  }
1699
1700
  }
1701
+ handleCheckboxState(li, checkIcon, checkboxElement, isCheckedBefore, isFocusedBefore, eventArgs, isSetCheckboxLI, textAreaFocus) {
1702
+ this.trigger('select', eventArgs, (observedArgs) => {
1703
+ if (observedArgs.cancel) {
1704
+ if (isSetCheckboxLI ? isCheckedBefore : !isCheckedBefore) {
1705
+ checkIcon.classList.add(classNames.checked);
1706
+ li.classList.add(classNames.selected);
1707
+ }
1708
+ else {
1709
+ checkIcon.classList.remove(classNames.checked);
1710
+ li.classList.remove(classNames.selected);
1711
+ }
1712
+ checkboxElement.setAttribute('aria-checked', isSetCheckboxLI ? (isCheckedBefore ? 'true' : 'false') : (isCheckedBefore ? 'false' : 'true'));
1713
+ merge(eventArgs, { isChecked: checkIcon.classList.contains(classNames.checked) });
1714
+ if (isFocusedBefore) {
1715
+ li.classList.remove(classNames.focused);
1716
+ if (textAreaFocus) {
1717
+ textAreaFocus.classList.remove('e-focused');
1718
+ }
1719
+ }
1720
+ }
1721
+ });
1722
+ }
1700
1723
  clickHandler(e) {
1701
1724
  if (Array.isArray(this.dataSource) && this.dataSource.length === 0) {
1702
1725
  return;
@@ -1738,7 +1761,10 @@ let ListView = class ListView extends Component {
1738
1761
  const eventArgs = this.selectEventData(li, e);
1739
1762
  const checkIcon = li.querySelector('.' + classNames.checkboxIcon);
1740
1763
  merge(eventArgs, { isChecked: checkIcon.classList.contains(classNames.checked) });
1741
- this.trigger('select', eventArgs);
1764
+ const checkboxElement = li.querySelector('.' + classNames.checkboxWrapper);
1765
+ const isCheckedBefore = checkIcon.classList.contains(classNames.checked);
1766
+ const isFocusedBefore = li.classList.contains(classNames.focused);
1767
+ this.handleCheckboxState(li, checkIcon, checkboxElement, isCheckedBefore, isFocusedBefore, eventArgs, false);
1742
1768
  }
1743
1769
  }
1744
1770
  else if (li.classList.contains(classNames.hasChild)) {
@@ -1958,7 +1984,13 @@ let ListView = class ListView extends Component {
1958
1984
  }
1959
1985
  const eventArgs = this.selectEventData(li, e);
1960
1986
  merge(eventArgs, { isChecked: checkIcon ? checkIcon.classList.contains(classNames.checked) : false });
1961
- this.trigger('select', eventArgs);
1987
+ if (!isNullOrUndefined(li)) {
1988
+ const cbElement = li.querySelector('.' + classNames.checkboxWrapper);
1989
+ const checkboxIcon = li.querySelector('.' + classNames.checkboxIcon);
1990
+ const isCheckedBefore = checkboxIcon.classList.contains(classNames.checked);
1991
+ const isFocusedBefore = li.classList.contains(classNames.focused);
1992
+ this.handleCheckboxState(li, checkboxIcon, cbElement, isCheckedBefore, isFocusedBefore, eventArgs, false);
1993
+ }
1962
1994
  this.updateSelectedId();
1963
1995
  }
1964
1996
  }
@@ -2033,8 +2065,9 @@ let ListView = class ListView extends Component {
2033
2065
  if (!isNullOrUndefined(this.scroll)) {
2034
2066
  EventHandler.remove(this.element, 'scroll', this.onListScroll);
2035
2067
  }
2036
- if (this.touchModule)
2068
+ if (this.touchModule) {
2037
2069
  this.touchModule.destroy();
2070
+ }
2038
2071
  this.touchModule = null;
2039
2072
  }
2040
2073
  removeFocus() {
@@ -2085,7 +2118,9 @@ let ListView = class ListView extends Component {
2085
2118
  const checkboxElement = li.querySelector('.' + classNames.checkboxWrapper);
2086
2119
  const checkIcon = checkboxElement.querySelector('.' + classNames.checkboxIcon + '.' + classNames.icon);
2087
2120
  this.removeHover();
2088
- if (!checkIcon.classList.contains(classNames.checked)) {
2121
+ const isCheckedBefore = checkIcon.classList.contains(classNames.checked);
2122
+ const isFocusedBefore = li.classList.contains(classNames.focused);
2123
+ if (!isCheckedBefore) {
2089
2124
  checkIcon.classList.add(classNames.checked);
2090
2125
  li.classList.add(classNames.selected);
2091
2126
  }
@@ -2100,7 +2135,7 @@ let ListView = class ListView extends Component {
2100
2135
  if (this.enableVirtualization) {
2101
2136
  this.virtualizationModule.setCheckboxLI(li, e);
2102
2137
  }
2103
- this.trigger('select', eventArgs);
2138
+ this.handleCheckboxState(li, checkIcon, checkboxElement, isCheckedBefore, isFocusedBefore, eventArgs, true, textAreaFocus);
2104
2139
  this.setSelectedItemData(li);
2105
2140
  this.renderSubList(li);
2106
2141
  }
@@ -2168,6 +2203,10 @@ let ListView = class ListView extends Component {
2168
2203
  this.selectedLI = li;
2169
2204
  this.renderSubList(li);
2170
2205
  }
2206
+ else {
2207
+ li.classList.remove(classNames.selected);
2208
+ this.selectedLI = li;
2209
+ }
2171
2210
  });
2172
2211
  }
2173
2212
  }
@@ -2381,6 +2420,9 @@ let ListView = class ListView extends Component {
2381
2420
  let ele = this.element.querySelector('[pid=\'' + uID + '\']');
2382
2421
  this.curDSLevel.push(uID);
2383
2422
  this.setViewDataSource(this.getSubDS());
2423
+ if (this.enableVirtualization) {
2424
+ this.virtualizationModule.updateDOMItemCount();
2425
+ }
2384
2426
  if (!ele) {
2385
2427
  const data = this.curViewDS;
2386
2428
  ele = ListBase.createListFromJson(this.createElement, data, this.listBaseOption, this.curDSLevel.length, null, this);
@@ -2489,6 +2531,9 @@ let ListView = class ListView extends Component {
2489
2531
  }
2490
2532
  this.curDSLevel.pop();
2491
2533
  this.setViewDataSource(this.getSubDS());
2534
+ if (this.enableVirtualization) {
2535
+ this.virtualizationModule.updateDOMItemCount();
2536
+ }
2492
2537
  let toUL = this.element.querySelector('[data-uid=\'' + pID + '\']');
2493
2538
  const fromUL = this.curUL;
2494
2539
  if (!toUL) {
@@ -3182,18 +3227,21 @@ class Virtualization {
3182
3227
  */
3183
3228
  uiVirtualization() {
3184
3229
  this.wireScrollEvent(false);
3230
+ const isRendered = this.listViewInstance.isRendered;
3231
+ const firstIndex = isRendered && !isNullOrUndefined(this.uiFirstIndex) ? this.uiFirstIndex : 0;
3185
3232
  const curViewDS = this.listViewInstance.curViewDS;
3186
- const firstDs = curViewDS.slice(0, 1);
3233
+ const firstDs = curViewDS.slice(firstIndex, firstIndex + 1);
3187
3234
  this.listViewInstance.ulElement = this.listViewInstance.curUL = ListBase.createList(this.listViewInstance.createElement, firstDs, this.listViewInstance.listBaseOption, null, this.listViewInstance);
3188
3235
  this.listViewInstance.contentContainer = this.listViewInstance.createElement('div', { className: classNames.container });
3189
3236
  this.listViewInstance.element.appendChild(this.listViewInstance.contentContainer);
3190
3237
  this.listViewInstance.contentContainer.appendChild(this.listViewInstance.ulElement);
3191
3238
  this.listItemHeight = this.listViewInstance.ulElement.firstElementChild.getBoundingClientRect().height;
3192
3239
  this.expectedDomItemCount = this.ValidateItemCount(10000);
3193
- this.domItemCount = this.ValidateItemCount(Object.keys(this.listViewInstance.curViewDS).length);
3194
- this.uiFirstIndex = 0;
3195
- this.uiLastIndex = this.domItemCount - 1;
3196
- const otherDs = curViewDS.slice(1, this.domItemCount);
3240
+ this.updateDOMItemCount();
3241
+ const lastIndex = isRendered && !isNullOrUndefined(this.uiLastIndex) ? this.uiLastIndex : this.domItemCount - 1;
3242
+ this.uiFirstIndex = firstIndex;
3243
+ this.uiLastIndex = lastIndex;
3244
+ const otherDs = curViewDS.slice(firstIndex + 1, lastIndex + 1);
3197
3245
  const listItems = ListBase.createListItemFromJson(this.listViewInstance.createElement, otherDs, this.listViewInstance.listBaseOption, null, null, this.listViewInstance);
3198
3246
  append(listItems, this.listViewInstance.ulElement);
3199
3247
  this.listViewInstance.liCollection = this.listViewInstance.curUL.querySelectorAll('li');
@@ -3202,11 +3250,14 @@ class Virtualization {
3202
3250
  this.bottomElement = this.listViewInstance.createElement('div');
3203
3251
  this.listViewInstance.ulElement.insertBefore(this.bottomElement, null);
3204
3252
  this.totalHeight = (Object.keys(curViewDS).length * this.listItemHeight) - (this.domItemCount * this.listItemHeight);
3205
- this.topElement.style.height = 0 + 'px';
3206
- this.bottomElement.style.height = this.totalHeight + 'px';
3207
- this.topElementHeight = 0;
3208
- this.bottomElementHeight = this.totalHeight;
3209
- this.listDiff = 0;
3253
+ this.topElement.style.height = isRendered ? this.topElementHeight + 'px' : '0px';
3254
+ this.bottomElement.style.height = isRendered ? (this.totalHeight - this.topElementHeight) + 'px' : this.totalHeight + 'px';
3255
+ this.topElementHeight = isRendered ? this.topElementHeight : 0;
3256
+ this.bottomElementHeight = isRendered ? (this.totalHeight - this.topElementHeight) : this.totalHeight;
3257
+ this.listDiff = isRendered ? this.listDiff : 0;
3258
+ if (isRendered) {
3259
+ this.listViewInstance.element.scrollTop = this.listViewInstance.previousScrollTop;
3260
+ }
3210
3261
  this.uiIndicesInitialization();
3211
3262
  }
3212
3263
  wireScrollEvent(destroy) {
@@ -3248,6 +3299,9 @@ class Virtualization {
3248
3299
  }
3249
3300
  return itemCount;
3250
3301
  }
3302
+ updateDOMItemCount() {
3303
+ this.domItemCount = this.ValidateItemCount(Object.keys(this.listViewInstance.curViewDS).length);
3304
+ }
3251
3305
  uiIndicesInitialization() {
3252
3306
  this.uiIndices = { 'activeIndices': [], 'disabledItemIndices': [], 'hiddenItemIndices': [] };
3253
3307
  const data = this.listViewInstance.curViewDS;
@@ -3585,12 +3639,26 @@ class Virtualization {
3585
3639
  };
3586
3640
  }
3587
3641
  if (this.listViewInstance.showCheckBox) {
3588
- eventArgs.isChecked = isChecked;
3589
- this.listViewInstance.trigger('select', eventArgs);
3642
+ this.listViewInstance.trigger('select', eventArgs, (observedArgs) => {
3643
+ if (observedArgs.cancel) {
3644
+ if (!isChecked) {
3645
+ eventArgs.isChecked = isChecked;
3646
+ this.uiIndices.activeIndices.push(resutJSON.index);
3647
+ }
3648
+ else {
3649
+ eventArgs.isChecked = !isChecked;
3650
+ this.uiIndices.activeIndices.splice(this.uiIndices.activeIndices.indexOf(resutJSON.index), 1);
3651
+ }
3652
+ }
3653
+ });
3590
3654
  }
3591
3655
  else if (!isSelected) {
3592
3656
  this.listViewInstance.removeSelect();
3593
- this.listViewInstance.trigger('select', eventArgs);
3657
+ this.listViewInstance.trigger('select', eventArgs, (observedArgs) => {
3658
+ if (observedArgs.cancel) {
3659
+ this.activeIndex = undefined;
3660
+ }
3661
+ });
3594
3662
  }
3595
3663
  }
3596
3664
  }