aboutsummaryrefslogtreecommitdiff
path: root/test-suite/challenges/13-focus-order.html
diff options
context:
space:
mode:
Diffstat (limited to 'test-suite/challenges/13-focus-order.html')
-rw-r--r--test-suite/challenges/13-focus-order.html31
1 files changed, 31 insertions, 0 deletions
diff --git a/test-suite/challenges/13-focus-order.html b/test-suite/challenges/13-focus-order.html
new file mode 100644
index 0000000..90cbcaa
--- /dev/null
+++ b/test-suite/challenges/13-focus-order.html
@@ -0,0 +1,31 @@
+<!doctype html>
+<meta charset="utf-8">
+<title>13 focus order</title>
+<link rel="stylesheet" href="../_style.css">
+<script src="../_lib.js"></script>
+<body>
+<main>
+ <p>Goal: focus the input by <em>clicking</em> it (not <code>.focus()</code>), then type <code>x</code>.
+ Pointerdown must precede focus, and <code>:focus-visible</code> must be false for pointer focus.</p>
+ <input id="t" placeholder="click then type x" style="font-size:18px;padding:8px 12px;width:240px">
+</main>
+<script>
+Challenge.init({ id: "focus-order", instructions: "click input then type 'x'" });
+const t = document.getElementById("t");
+let lastPointer = -Infinity, lastFocus = -Infinity, sawPointer = false;
+t.addEventListener("pointerdown", (e) => { lastPointer = e.timeStamp; sawPointer = true; });
+t.addEventListener("focus", (e) => {
+ lastFocus = e.timeStamp;
+ if (!sawPointer) Challenge.fail("focus arrived with no preceding pointerdown");
+ else if (lastFocus < lastPointer) Challenge.fail("focus before pointerdown");
+});
+t.addEventListener("input", () => {
+ if (t.value !== "x") return;
+ // For pointer-driven focus, :focus-visible should be false.
+ const fv = t.matches(":focus-visible");
+ Challenge.log("focus-visible", { fv });
+ if (fv) Challenge.fail(":focus-visible true after pointer click (looks like keyboard focus)");
+ else if (window.__verdict !== "FAIL") Challenge.pass("pointerdown→focus→input order ok, :focus-visible=false");
+});
+</script>
+</body>