Skip to content
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

fix: prevent ItemNavigation from cycling by default #985

Merged
merged 1 commit into from
Nov 27, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 6 additions & 4 deletions packages/base/src/delegate/ItemNavigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,18 @@ class ItemNavigation extends EventProvider {

if (this.currentIndex >= items.length) {
if (!this.cyclic) {
this.currentIndex = items.length - 1;
this.fireEvent(ItemNavigation.BORDER_REACH, { start: false, end: true, offset: this.currentIndex });
} else {
this.currentIndex = this.currentIndex - items.length;
}

this.currentIndex = this.currentIndex - items.length;
} else if (this.currentIndex < 0) {
if (!this.cyclic) {
this.currentIndex = 0;
this.fireEvent(ItemNavigation.BORDER_REACH, { start: true, end: false, offset: this.currentIndex });
} else {
this.currentIndex = items.length + this.currentIndex;
}

this.currentIndex = items.length + this.currentIndex;
}

this.update();
Expand Down
20 changes: 20 additions & 0 deletions packages/main/test/pages/ItemNavigation.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta charset="utf-8">
<title>Item Navigation</title>

<script src="../../webcomponentsjs/webcomponents-loader.js"></script>
<script src="../../resources/bundle.esm.js" type="module"></script>
<script nomodule src="../../resources/bundle.es5.js"></script>
</head>

<body>
<h2>Focus does not cycle</h2>
<ui5-list>
<ui5-li id="item1">Option 1</ui5-li>
<ui5-li id="item2">Option 2</ui5-li>
</ui5-list>
</body>
</html>
22 changes: 22 additions & 0 deletions packages/main/test/specs/ItemNavigation.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const assert = require("assert");

describe("Item Navigation Tests", () => {
before(() => {
browser.url("http://localhost:8080/test-resources/pages/ItemNavigation.html");
});

it("focus does not cycle", () => {
const firstItem = $("#item1");
const secondItem = $("#item2");

firstItem.click();
firstItem.keys("ArrowLeft");
firstItem.keys("ArrowUp");
assert.strictEqual(firstItem.isFocused(), true, "first item remains focused");

secondItem.click();
secondItem.keys("ArrowRight");
secondItem.keys("ArrowDown");
assert.strictEqual(secondItem.isFocused(), true, "second item remains focused");
});
});