Skip to content

Commit 0684cbe

Browse files
List: fix animation on collapse group (T1282693) (DevExpress#29815)
1 parent 20f11ca commit 0684cbe

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

packages/devextreme/js/__internal/ui/list/m_list.base.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ export const ListBase = CollectionWidget.inherit({
419419
},
420420

421421
_scrollHandler(e) {
422-
this._scrollAction && this._scrollAction(e);
422+
this._scrollAction?.(e);
423423
},
424424

425425
_initTemplates() {
@@ -495,7 +495,7 @@ export const ListBase = CollectionWidget.inherit({
495495
});
496496
} else {
497497
clearTimeout(this._showLoadingIndicatorTimer);
498-
this._scrollView && this._scrollView.finishLoading();
498+
this._scrollView?.finishLoading();
499499
}
500500
if (!isLoading) {
501501
this._isDataSourceFirstLoadCompleted(false);
@@ -504,7 +504,7 @@ export const ListBase = CollectionWidget.inherit({
504504

505505
_dataSourceChangedHandler() {
506506
if (!this._shouldAppendItems() && hasWindow()) {
507-
this._scrollView && this._scrollView.scrollTo(0);
507+
this._scrollView?.scrollTo(0);
508508
}
509509

510510
this.callBase.apply(this, arguments);
@@ -623,21 +623,27 @@ export const ListBase = CollectionWidget.inherit({
623623
_collapseGroupHandler($group, toggle) {
624624
const deferred = Deferred();
625625

626-
if ($group.hasClass(LIST_GROUP_COLLAPSED_CLASS) === toggle) {
626+
const collapsed = $group.hasClass(LIST_GROUP_COLLAPSED_CLASS);
627+
628+
if (collapsed === toggle) {
627629
return deferred.resolve();
628630
}
629631

630632
const $groupBody = $group.children(`.${LIST_GROUP_BODY_CLASS}`);
631-
632633
const startHeight = getOuterHeight($groupBody);
633634
let endHeight = 0;
634-
if (startHeight === 0) {
635+
636+
if (collapsed) {
635637
setHeight($groupBody, 'auto');
636638
endHeight = getOuterHeight($groupBody);
637639
}
638640

639641
$group.toggleClass(LIST_GROUP_COLLAPSED_CLASS, toggle);
640642

643+
if (fx.isAnimating($groupBody)) {
644+
fx.stop($groupBody, false);
645+
}
646+
641647
fx.animate($groupBody, {
642648
// @ts-expect-error
643649
type: 'custom',

packages/devextreme/testing/tests/DevExpress.ui.widgets/listParts/commonTests.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,34 @@ QUnit.module('collapsible groups', moduleSetup, () => {
296296
assert.ok(!$group.hasClass(LIST_GROUP_COLLAPSED_CLASS), 'collapsed class is not present');
297297
});
298298

299+
QUnit.test('group body should be correctly collapsed on fast multiple clicks on header (T1282693)', function(assert) {
300+
this.clock.restore();
301+
const done = assert.async();
302+
303+
const $element = this.element.dxList({
304+
items: [{ key: 'a', items: ['0'] }],
305+
grouped: true,
306+
collapsibleGroups: true
307+
});
308+
309+
const $group = $element.find('.' + LIST_GROUP_CLASS);
310+
const $groupBody = $group.find('.' + LIST_GROUP_BODY_CLASS);
311+
const $groupHeader = $element.find('.' + LIST_GROUP_HEADER_CLASS);
312+
313+
const animationDuration = 200;
314+
315+
for(let i = 0; i < 11; i++) {
316+
$groupHeader.trigger('dxclick');
317+
}
318+
319+
setTimeout(() => {
320+
assert.strictEqual($group.hasClass(LIST_GROUP_COLLAPSED_CLASS), true, 'collapsed class is present');
321+
assert.strictEqual($groupBody.height(), 0, 'group items are hidden');
322+
323+
done();
324+
}, 2 * animationDuration);
325+
});
326+
299327
QUnit.test('group body should be not collapsed by click on header if collapsibleGroups is disabled', function(assert) {
300328
const $element = this.element.dxList({
301329
items: [{ key: 'a', items: ['0'] }],

0 commit comments

Comments
 (0)