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 4 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
3 changes: 2 additions & 1 deletion packages/devextreme/js/__internal/ui/m_multi_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,9 @@ const MultiView = CollectionWidget.inherit({

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

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

return index;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,56 @@ QUnit.module('loop', {
delete this.animationStartAction;
}
}, () => {
QUnit.test('if first item is invisible and swiped right last item should be selected', function(assert) {
const $multiView = $('#multiView').dxMultiView({
items: [
{ text: '1', visible: false },
{ text: '2', visible: true },
{ text: '3', visible: true }
],
loop: true,
selectedIndex: 1
});

const instance = $multiView.dxMultiView('instance');
const $firstItem = $multiView.find(`.${MULTIVIEW_ITEM_CLASS}`).eq(1);
const $lastItem = $multiView.find(`.${MULTIVIEW_ITEM_CLASS}`).eq(2);
const pointer = pointerMock($multiView);

this.animationStartAction = function() {
assert.equal(position($firstItem), 0, 'first visible item has correct position');
assert.equal(position($lastItem), -800, 'last visible item has correct position');
};

pointer.start().swipeStart().swipe(0.1).swipeEnd(1);
assert.strictEqual(instance.option('selectedIndex'), 2, 'last item is selected');
});

QUnit.test('if last item is invisible and swiped left first item should be selected', function(assert) {
const $multiView = $('#multiView').dxMultiView({
items: [
{ text: '1', visible: true },
{ text: '2', visible: true },
{ text: '3', visible: false }
],
loop: true,
selectedIndex: 1
});

const instance = $multiView.dxMultiView('instance');
const $firstItem = $multiView.find(`.${MULTIVIEW_ITEM_CLASS}`).eq(0);
const $lastItem = $multiView.find(`.${MULTIVIEW_ITEM_CLASS}`).eq(1);
const pointer = pointerMock($multiView);

this.animationStartAction = function() {
assert.equal(position($firstItem), 800, 'first visible item has correct position');
assert.equal(position($lastItem), 0, 'last visible item has correct position');
};

pointer.start().swipeStart().swipe(-0.1).swipeEnd(-1);
assert.strictEqual(instance.option('selectedIndex'), 0, 'last item is selected');
});

QUnit.test('when only one item is visible, swipe action does not move the current visible item', function(assert) {
const $multiView = $('#multiView').dxMultiView({
items: [
Expand Down
Loading