Skip to content

MultiView: Fix search traversal of visible items during loop #28186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion packages/devextreme/js/__internal/ui/m_multi_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,22 @@ const MultiView = CollectionWidget.inherit({
index -= count;
}

const step = direction > 0 ? -1 : 1;
let step = direction > 0 ? -1 : 1;
const lastNotLoopedIndex = step === -1 ? 0 : count - 1;

if (loop) {
if (index === count - 1 && !this._isItemVisible(index)) {
step = 1;
} else if (index === 0 && !this._isItemVisible(index)) {
step = -1;
}
}

while (!this._isItemVisible(index) && (loop || index !== lastNotLoopedIndex)) {
index = (index + step) % count;
if (index < 0) {
index = count - 1;
}
}

return index;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1838,6 +1838,20 @@ QUnit.module('selectedIndex vs item.visible', () => {

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

QUnit.test('if first visible item is not visible and loop = true it should traverse backward search for last visible item', function(assert) {
const $multiView = $('#multiView').dxMultiView({
items: [
{ text: '1', visible: false },
{ text: '2', visible: true },
{ text: '3', visible: true }
],
loop: true
});
const instance = $multiView.dxMultiView('instance');

assert.strictEqual(instance.option('selectedIndex'), 2, 'selectedIndex is updated on proper index');
});
});

QUnit.module('on runtime', () => {
Expand Down Expand Up @@ -1983,5 +1997,20 @@ QUnit.module('selectedIndex vs item.visible', () => {

assert.strictEqual(instance.option('selectedIndex'), 0, 'selectedIndex is not changed');
});

QUnit.test('if first visible item is not visible and loop = true it should traverse backward search for last visible item', function(assert) {
const $multiView = $('#multiView').dxMultiView({
items: [
{ text: '1', visible: true },
{ text: '2', visible: true },
{ text: '3', visible: true }
],
loop: true
});
const instance = $multiView.dxMultiView('instance');
instance.option('items[0].visible', false);

assert.strictEqual(instance.option('selectedIndex'), 2, 'selectedIndex is updated on proper index');
});
});
});
Loading