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 linear moves #10

Merged
merged 3 commits into from
Aug 26, 2024
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
32 changes: 32 additions & 0 deletions cypress/e2e/spec.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,38 @@ describe("focus-shift spec", () => {
])
)

it(
"linear-type group with stretched item LR",
testFor("./cypress/fixtures/group-linear-stretch.html", { className: "rows" }, [
{ eventType: "keydown", selector: "#button-big", options: keyevent({ key: "ArrowLeft" }) },
{ eventType: "keydown", selector: "#button-small", options: keyevent({ key: "ArrowDown" }) }
])
)

it(
"linear-type group with stretched item RL",
testFor("./cypress/fixtures/group-linear-stretch.html", { className: "rows" }, [
{ eventType: "keydown", selector: "#button-big", options: keyevent({ key: "ArrowRight" }) },
{ eventType: "keydown", selector: "#button-small", options: keyevent({ key: "ArrowDown" }) }
])
)

it(
"linear-type group with stretched item TD",
testFor("./cypress/fixtures/group-linear-stretch.html", { className: "columns" }, [
{ eventType: "keydown", selector: "#button-big", options: keyevent({ key: "ArrowDown" }) },
{ eventType: "keydown", selector: "#button-small", options: keyevent({ key: "ArrowRight" }) }
])
)

it(
"linear-type group with stretched item DT",
testFor("./cypress/fixtures/group-linear-stretch.html", { className: "columns" }, [
{ eventType: "keydown", selector: "#button-big", options: keyevent({ key: "ArrowUp" }) },
{ eventType: "keydown", selector: "#button-small", options: keyevent({ key: "ArrowRight" }) }
])
)

it(
"memorize-type group TD",
testFor("./cypress/fixtures/group-memorize.html", { className: "rows" }, [
Expand Down
29 changes: 29 additions & 0 deletions cypress/fixtures/group-linear-stretch.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="stylesheet" href="styles.css" />
<style>
.nav-group {
width: 800px;
height: 600px;
}
#button-big {
align-self: stretch;
}
#button-small {
align-self: center;
}
</style>
</head>
<body>
<!-- With two group items, one spanning the entire length along the
direction of movement, we expect this expansive item to be chosen.
-->
<div class="nav-group" data-focus-group="linear">
<button id="button-big">Big Button</button>
<button id="button-small">Small Button</button>
</div>
<script src="../../index.js"></script>
</body>
</html>
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function handleUserDirection(direction) {
* Standard heuristics are used to determine which element should be the first to receive focus.
*
* 1. Look for elements with explicit tabindex attribute set, choose lowest index > 0
* 2. If no tabindex was set, treat container as a 'first' group
* 2. If no tabindex was set, treat container as a 'linear' group
*
* @param {Direction} direction
* @param {Element} container
Expand Down Expand Up @@ -515,7 +515,7 @@ function focusActiveElement(direction, origin, group) {
function focusLinear(direction, origin, group) {
const originPoint = makeOrigin(opposite(direction), origin)
const candidates = getFocusableElements(group).map((candidate) =>
annotate(opposite(direction), origin, candidate)
annotate(direction, origin, candidate)
)
const bestCandidate = getMinimumBy(candidates, (candidate) =>
euclidean(originPoint, candidate.point)
Expand Down
Loading