Skip to content

armgit / kwant

Public Imported from GitHub
0

Your own team of AI bots in one self-hosted binary: spaces, every account you have, handoffs, approvals and routines. Open-source, self-hosted alternative to Grok Bot, Claude Duet and OpenAI dots. Rust + React.

On a phone, a fold's title sits in the middle of its row (28d) (#791)

Oleksandr Ivanchenko034c60ed6a46
diff --git a/frontend/src/components/ActivityList.tsx b/frontend/src/components/ActivityList.tsx
index 6c48f261..0e26df7e 100644
--- a/frontend/src/components/ActivityList.tsx
+++ b/frontend/src/components/ActivityList.tsx
@@ -181,7 +181,7 @@ const StepRow: React.FC<{ step: ActivityStep; live?: LiveActivity; now: number;
>
{step.detail ? (
<details className="group" open={opened || undefined}>
- <summary className="flex items-start gap-2 cursor-pointer list-none rounded [&::-webkit-details-marker]:hidden focus-visible:outline focus-visible:outline-2 focus-visible:outline-sky-400">
+ <summary className="flex items-start [@media(max-width:767px)_and_(pointer:coarse)]:items-center gap-2 cursor-pointer list-none rounded [&::-webkit-details-marker]:hidden focus-visible:outline focus-visible:outline-2 focus-visible:outline-sky-400">
{head}
<ChevronRight size={13} className="mt-px flex-shrink-0 text-zinc-400 transition-transform motion-reduce:transition-none group-open:rotate-90" aria-hidden="true" />
</summary>
diff --git a/frontend/src/styles/modern.css b/frontend/src/styles/modern.css
index c19eef0c..472677e2 100644
--- a/frontend/src/styles/modern.css
+++ b/frontend/src/styles/modern.css
@@ -186,6 +186,11 @@
:is(button, [role='button'], [role='tab'], [role='menuitem'], [role='option'], select, summary):not([role='switch'], [data-compact], .prose *) {
min-height: 44px;
}
+ /* A 44 px fold keeps its title in the middle of the row, not stuck to the top (plain block summaries;
+ flex ones centre themselves with items-center) */
+ summary {
+ align-content: center;
+ }
/* Icon-only buttons get the width too, with the icon centred */
button:not([role='switch'], [role='menuitem'], [data-compact], .hidden, .w-full, :has(> :not(svg, img, .sr-only, .hidden))):has(> svg, > img) {
min-width: 44px;
diff --git a/frontend/tests/touchFolds.test.mjs b/frontend/tests/touchFolds.test.mjs
new file mode 100644
index 00000000..3f879b9a
--- /dev/null
+++ b/frontend/tests/touchFolds.test.mjs
@@ -0,0 +1,103 @@
+// Phone folds stay centred (28d, Nov 17). On a touch phone, modern.css's (max-width: 767px) and (pointer: coarse)
+// block gives every <summary> a 44 px min height for tapping. A plain block summary then keeps its title at the top
+// of that box with ~30 px empty under it, and a flex summary with items-start does the same. So:
+// (a) that phone block sets `align-content: center` on `summary` (block summaries centre in the 44 px row), and
+// (b) every <summary> in frontend/src whose className has `flex` or `inline-flex` also centres its items:
+// `items-center`, the phone-only `[@media(max-width:767px)_and_(pointer:coarse)]:items-center`, or it is a
+// `data-compact` control (which the 44 px rule skips).
+import assert from 'node:assert/strict';
+import test from 'node:test';
+import { readFileSync, readdirSync, statSync } from 'node:fs';
+import { join, relative } from 'node:path';
+import { fileURLToPath } from 'node:url';
+
+const root = fileURLToPath(new URL('..', import.meta.url));
+const src = join(root, 'src');
+const PHONE_QUERY = '(max-width: 767px) and (pointer: coarse)';
+
+// The bodies of every @media block with exactly this query, by brace matching.
+export function mediaBlocks(css, query) {
+ const out = [];
+ for (let at = css.indexOf(`@media ${query}`); at >= 0; at = css.indexOf(`@media ${query}`, at + 1)) {
+ const open = css.indexOf('{', at);
+ let depth = 0;
+ for (let i = open; i < css.length; i++) {
+ if (css[i] === '{') depth++;
+ else if (css[i] === '}' && --depth === 0) { out.push(css.slice(open + 1, i)); break; }
+ }
+ }
+ return out;
+}
+// The phone block that holds the 44 px touch-target rule (modern.css has more than one block with this query).
+export function touchBlock(css) {
+ return mediaBlocks(css, PHONE_QUERY).find((b) => /\bsummary\b[^{}]*\{[^{}]*min-height:\s*44px/.test(b)) ?? null;
+}
+
+// True when the block has a rule whose selector list includes a bare `summary` and whose body sets align-content: center.
+export function centresSummaries(block) {
+ const clean = block.replace(/\/\*[\s\S]*?\*\//g, '');
+ for (const m of clean.matchAll(/([^{}]+)\{([^{}]*)\}/g)) {
+ const sels = m[1].split(',').map((s) => s.trim());
+ if (sels.includes('summary') && /(^|;)\s*align-content\s*:\s*center\s*(;|$)/.test(m[2].trim())) return true;
+ }
+ return false;
+}
+
+const PHONE_CENTRE = '[@media(max-width:767px)_and_(pointer:coarse)]:items-center';
+// The className of a <summary> tag that starts at `text` (the tag's first few lines), or null.
+export function summaryClass(text) {
+ const tag = text.slice(0, text.search(/>\s*($|[^=])/) + 1 || 600);
+ const m = tag.match(/className=(?:"([^"]*)"|\{`([^`]*)`\}|\{'([^']*)'\}|\{"([^"]*)"\})/);
+ return m ? { cls: m[1] ?? m[2] ?? m[3] ?? m[4], compact: /\bdata-compact\b/.test(tag) } : null;
+}
+// A problem string, or null when the summary is fine.
+export function flexSummaryProblem(text) {
+ const s = summaryClass(text);
+ if (!s) return null;
+ const tokens = s.cls.split(/\s+/);
+ if (!tokens.some((t) => t === 'flex' || t === 'inline-flex')) return null;
+ if (s.compact || tokens.includes('items-center') || tokens.includes(PHONE_CENTRE)) return null;
+ return `flex <summary> without items-center: on a touch phone it is 44 px tall and its title sticks to the top. Add ${PHONE_CENTRE} (or items-center).`;
+}
+
+const walk = (d) =>
+ readdirSync(d).flatMap((n) => {
+ const p = join(d, n);
+ return statSync(p).isDirectory() ? (n === 'generated' ? [] : walk(p)) : /\.(tsx|ts)$/.test(n) ? [p] : [];
+ });
+
+test('the phone block centres a 44 px summary (align-content: center)', () => {
+ const css = readFileSync(join(src, 'styles/modern.css'), 'utf8');
+ const block = touchBlock(css);
+ assert.ok(block, `modern.css has no @media ${PHONE_QUERY} block with the 44 px summary rule`);
+ assert.ok(centresSummaries(block), `@media ${PHONE_QUERY} in modern.css must set summary { align-content: center; } so a fold's title sits in the middle of its 44 px row`);
+});
+
+test('every flex <summary> centres its items on a touch phone', () => {
+ const hits = [];
+ for (const f of walk(src)) {
+ const text = readFileSync(f, 'utf8');
+ for (const m of text.matchAll(/<summary\b/g)) {
+ const problem = flexSummaryProblem(text.slice(m.index, m.index + 800).split('\n').slice(0, 6).join('\n'));
+ if (problem) hits.push(`${relative(root, f)}:${text.slice(0, m.index).split('\n').length}: ${problem}`);
+ }
+ }
+ assert.deepEqual(hits, []);
+});
+
+test('unit: the helpers', () => {
+ const ok = '@media (max-width: 767px) and (pointer: coarse) {\n summary { min-height: 44px; }\n /* x */\n summary {\n align-content: center;\n }\n}';
+ assert.equal(centresSummaries(touchBlock(ok)), true);
+ assert.equal(centresSummaries(touchBlock(ok.replace('align-content: center', 'align-content: start'))), false);
+ assert.equal(centresSummaries('details summary { align-content: center; }'), false);
+ assert.equal(touchBlock('a{}'), null);
+ assert.equal(mediaBlocks(`@media ${PHONE_QUERY} { a { b: c; } }\n@media ${PHONE_QUERY} { d { e: f; } }`, PHONE_QUERY).length, 2);
+ assert.ok(flexSummaryProblem('<summary className="flex items-start gap-2">'));
+ assert.ok(flexSummaryProblem('<summary className={`inline-flex gap-1 ${x}`}>'));
+ assert.equal(flexSummaryProblem('<summary className="flex items-center gap-2">'), null);
+ assert.equal(flexSummaryProblem(`<summary className="flex items-start ${PHONE_CENTRE} gap-2">`), null);
+ assert.equal(flexSummaryProblem('<summary data-compact className="flex items-start">'), null);
+ assert.equal(flexSummaryProblem('<summary className="cursor-pointer flex-1">'), null);
+ assert.equal(flexSummaryProblem('<summary className="cursor-pointer">Details</summary>'), null);
+ assert.equal(flexSummaryProblem('<summary>Details</summary>'), null);
+});