Skip to content

Commit

Permalink
restore behavior on items change
Browse files Browse the repository at this point in the history
  • Loading branch information
ksercs committed Oct 14, 2024
1 parent f7427e7 commit c35176c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
20 changes: 11 additions & 9 deletions packages/devextreme/js/__internal/ui/m_multi_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,9 @@ const MultiView = CollectionWidget.inherit({
},

_ensureSelectedItemIsVisible(): void {
const { items, selectedIndex, loop } = this.option();
let currentSelectedIndex = selectedIndex;
const { items, loop, selectedIndex: currentSelectedIndex } = this.option();

const indexOverflowed = currentSelectedIndex >= items.length;
if (!indexOverflowed && this._isItemVisible(currentSelectedIndex)) {
if (this._isItemVisible(currentSelectedIndex)) {
return;
}

Expand All @@ -157,10 +155,6 @@ const MultiView = CollectionWidget.inherit({
return;
}

if (indexOverflowed) {
currentSelectedIndex = items.length - 1;
}

const direction = -1 * this._getRTLSignCorrection();
let newSelectedIndex = this._normalizeIndex(currentSelectedIndex, direction, loop);
if (newSelectedIndex === currentSelectedIndex) {
Expand Down Expand Up @@ -536,6 +530,15 @@ const MultiView = CollectionWidget.inherit({
this.callBase();
},

_itemOptionChanged(item, property) {
this.callBase(arguments);

const { selectedItem } = this.option();
if (property === 'visible' && item === selectedItem) {
this._ensureSelectedItemIsVisible();
}
},

_optionChanged(args) {
const { value } = args;

Expand All @@ -552,7 +555,6 @@ const MultiView = CollectionWidget.inherit({
this._invalidate();
break;
case 'items':
this._ensureSelectedItemIsVisible();
this._updateSwipeDisabledState();
this._findBoundaryIndices();
this.callBase(args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1862,7 +1862,7 @@ QUnit.module('selectedIndex vs item.visible', () => {
assert.strictEqual(instance.option('selectedIndex'), 0, 'selectedIndex is updated on proper index');
});

QUnit.test('when removing items selectedIndex should be on last visible item', function(assert) {
QUnit.test('after removing selected item selectedIndex should be restored to 0', function(assert) {
const $multiView = $('#multiView').dxMultiView({
items: [
{ text: '1', visible: true },
Expand All @@ -1877,7 +1877,7 @@ QUnit.module('selectedIndex vs item.visible', () => {
{ text: '2', visible: true },
]);

assert.strictEqual(instance.option('selectedIndex'), 1, 'selectedIndex is updated on proper index');
assert.strictEqual(instance.option('selectedIndex'), 0, 'selectedIndex is not changed');
});
});
});

0 comments on commit c35176c

Please sign in to comment.