Skip to content

Open-source, local-first social media research agent for Instagram, TikTok, and LinkedIn. Jev routes read-only steps; socai CLI captures cited browser evidence.

fix: focus the results workspace on entry (#81)

Asklv719590c1ffd1
diff --git a/package.json b/package.json
index 599fc97..9f9be9a 100644
--- a/package.json
+++ b/package.json
@@ -43,7 +43,7 @@
"dev": "node --watch ./bin/jev-social.js serve --no-open",
"benchmark:run": "node ./benchmark/run.js",
"benchmark:summarize": "node ./benchmark/summary.js",
- "check": "node --check ./bin/jev-social.js && node --check ./benchmark/run.js && node --check ./benchmark/schema.js && node --check ./benchmark/summary.js && node --check ./src/server.js && node --check ./src/decision-provider.js && node --check ./src/evidence.js && node --check ./src/report.js && node --check ./public/app.js && node --check ./public/evidence-preview.js && node --check ./public/run-route.js && node --check ./public/report-download.js && node --check ./public/report-stream.js && node --check ./public/prompts.js && node --check ./public/status.js",
+ "check": "node --check ./bin/jev-social.js && node --check ./benchmark/run.js && node --check ./benchmark/schema.js && node --check ./benchmark/summary.js && node --check ./src/server.js && node --check ./src/decision-provider.js && node --check ./src/evidence.js && node --check ./src/report.js && node --check ./public/app.js && node --check ./public/evidence-preview.js && node --check ./public/run-route.js && node --check ./public/report-download.js && node --check ./public/report-stream.js && node --check ./public/prompts.js && node --check ./public/status.js && node --check ./public/view-focus.js",
"test": "node --test"
},
"engines": {
diff --git a/public/app.js b/public/app.js
index 88fa32c..695e129 100644
--- a/public/app.js
+++ b/public/app.js
@@ -12,6 +12,7 @@ import {
import { bindPromptButtons, platformLabel, updatePromptButtons } from "./prompts.js";
import { parseRunRoute, resultHash } from "./run-route.js";
import { deriveStatusView } from "./status.js";
+import { revealWithInitialFocus } from "./view-focus.js";
const $ = (selector) => document.querySelector(selector);
const elements = {
@@ -168,7 +169,7 @@ function updateTimer() {
function showResultView({ push = false } = {}) {
elements.searchView.classList.add("hidden");
- elements.resultView.classList.remove("hidden");
+ revealWithInitialFocus(elements.resultView, $("#result-title"));
if (push && !parseRunRoute(location.hash)) history.pushState({ view: "results" }, "", `${location.pathname}${location.search}${resultHash()}`);
}
diff --git a/public/index.html b/public/index.html
index b775efa..6b80797 100644
--- a/public/index.html
+++ b/public/index.html
@@ -93,7 +93,7 @@
<button id="back-to-search" class="back-button" type="button">← New search</button>
<div class="result-heading">
<p class="eyebrow">SOCIAL RESULTS</p>
- <h2 id="result-title">Research in progress</h2>
+ <h2 id="result-title" tabindex="-1">Research in progress</h2>
</div>
<div class="time-readout"><small>ELAPSED</small><strong id="elapsed-time">0.0 s</strong></div>
</div>
diff --git a/public/styles.css b/public/styles.css
index ddd785c..292c6db 100644
--- a/public/styles.css
+++ b/public/styles.css
@@ -106,6 +106,7 @@ button:focus-visible,
.result-view { min-height: 0; display: flex; flex-direction: column; background: #fff; }
.result-toolbar { flex: 0 0 76px; display: grid; grid-template-columns: 180px 1fr 180px; align-items: center; gap: 20px; padding: 0 22px; border-bottom: 1px solid var(--ink); background: var(--ice); }
.result-heading { min-width: 0; text-align: center; }
+#result-title:focus { outline: 2px solid var(--ink); outline-offset: 3px; box-shadow: 0 0 0 6px var(--pink); }
.result-heading h2 { margin: 5px 0 0; overflow: hidden; font: 700 15px/1.2 var(--mono); letter-spacing: -.03em; text-overflow: ellipsis; white-space: nowrap; }
.back-button { justify-self: start; border: 0; padding: 8px 0; background: transparent; font: 700 11px var(--mono); }
.time-readout { justify-self: end; display: grid; text-align: right; }
diff --git a/public/view-focus.js b/public/view-focus.js
new file mode 100644
index 0000000..75223ad
--- /dev/null
+++ b/public/view-focus.js
@@ -0,0 +1,6 @@
+export function revealWithInitialFocus(view, focusTarget) {
+ const firstEntry = view.classList.contains("hidden");
+ view.classList.remove("hidden");
+ if (firstEntry) focusTarget.focus();
+ return firstEntry;
+}
diff --git a/test/view-focus.test.js b/test/view-focus.test.js
new file mode 100644
index 0000000..07136dc
--- /dev/null
+++ b/test/view-focus.test.js
@@ -0,0 +1,61 @@
+import assert from "node:assert/strict";
+import { readFile } from "node:fs/promises";
+import test from "node:test";
+
+import { revealWithInitialFocus } from "../public/view-focus.js";
+
+const indexHtml = await readFile(
+ new URL("../public/index.html", import.meta.url),
+ "utf8",
+);
+const stylesCss = await readFile(
+ new URL("../public/styles.css", import.meta.url),
+ "utf8",
+);
+
+function hiddenView() {
+ const classes = new Set(["hidden"]);
+ return {
+ classList: {
+ contains: (name) => classes.has(name),
+ remove: (name) => classes.delete(name),
+ add: (name) => classes.add(name),
+ },
+ };
+}
+
+test("the result heading can receive programmatic focus without entering the tab order", () => {
+ const heading = indexHtml.match(/<h2\b[^>]*\bid="result-title"[^>]*>/i)?.[0];
+ assert.ok(heading, "expected the result heading");
+ assert.match(heading, /\btabindex="-1"/i);
+});
+
+test("the programmatically focused result heading has a visible focus treatment", () => {
+ const rule = stylesCss.match(/#result-title:focus\s*\{([^}]*)\}/i)?.[1] ?? "";
+ assert.match(rule, /\boutline\s*:\s*[2-9]px\s+solid\s+var\(--ink\)/i);
+ assert.match(rule, /\bbox-shadow\s*:[^;]*var\(--pink\)/i);
+});
+
+test("entering results focuses once while streamed updates leave focus in place", () => {
+ const view = hiddenView();
+ let focusCount = 0;
+ const target = { focus: () => { focusCount += 1; } };
+
+ assert.equal(revealWithInitialFocus(view, target), true);
+ assert.equal(focusCount, 1);
+
+ assert.equal(revealWithInitialFocus(view, target), false);
+ assert.equal(focusCount, 1);
+});
+
+test("returning to search allows the next results entry to receive focus", () => {
+ const view = hiddenView();
+ let focusCount = 0;
+ const target = { focus: () => { focusCount += 1; } };
+
+ revealWithInitialFocus(view, target);
+ view.classList.add("hidden");
+ revealWithInitialFocus(view, target);
+
+ assert.equal(focusCount, 2);
+});