diff --git a/cypress/e2e/spec.cy.ts b/cypress/e2e/spec.cy.ts index 29d7adc..cd06ca9 100644 --- a/cypress/e2e/spec.cy.ts +++ b/cypress/e2e/spec.cy.ts @@ -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" }, [ diff --git a/cypress/fixtures/group-linear-stretch.html b/cypress/fixtures/group-linear-stretch.html new file mode 100644 index 0000000..577541b --- /dev/null +++ b/cypress/fixtures/group-linear-stretch.html @@ -0,0 +1,29 @@ + + +
+ + + + + + + + + + diff --git a/index.js b/index.js index 0e35450..7fe7072 100644 --- a/index.js +++ b/index.js @@ -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 @@ -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)