Skip to content

armgit / bento

Public Imported from GitHub
0

Bento, the office suite that fits in a file

spaces: the page tree says where you are, to everyone (#376)

nyblnet4776b23bcc30
diff --git a/scripts/test-spaces-model.ts b/scripts/test-spaces-model.ts
index d28520ac..0fc1b973 100644
--- a/scripts/test-spaces-model.ts
+++ b/scripts/test-spaces-model.ts
@@ -427,6 +427,23 @@ for (const [label, input, err] of [
}
}
+// ---- the page tree says where you are, to everyone -------------------------
+// `sp-here` renders the current page at weight 600 against 400. A sighted
+// reader gets that for free; a screen reader was told nothing, so the tree read
+// as a flat list of links with no indication which one you were on. Weight is
+// not an announcement. There are TWO places that set the class — the tree and
+// the archived list — and an attribute added to one of them is the kind of
+// half-fix that looks done.
+{
+ const fs = await import('node:fs')
+ const ed = fs.readFileSync(new URL('../spaces/src/editor.ts', import.meta.url), 'utf8')
+ const setsClass = (ed.match(/sp-here/g) ?? []).length
+ const setsAria = (ed.match(/setAttribute\('aria-current', 'page'\)/g) ?? []).length
+ ok(setsAria >= 2, `every row that can be current announces it (${setsAria} call sites)`)
+ ok(setsAria >= setsClass - 1,
+ 'no place styles itself as current without saying so — sp-here and aria-current stay paired')
+}
+
// ---- find & replace: the number shown IS the number changed ----------------
// Replace-all is destructive and lands in one commit, so the count in the
// readout, the count in the confirmation and the count of things that change
diff --git a/spaces/src/editor.ts b/spaces/src/editor.ts
index 37c16722..396b1741 100644
--- a/spaces/src/editor.ts
+++ b/spaces/src/editor.ts
@@ -987,7 +987,14 @@ export class Editor {
li.style.paddingInlineStart = `${depth * 14}px`
const a = document.createElement('a')
a.href = `#p/${page.id}`
- a.className = 'sp-treelink' + (page.id === s.pageId ? ' sp-here' : '')
+ const here = page.id === s.pageId
+ a.className = 'sp-treelink' + (here ? ' sp-here' : '')
+ // WEIGHT IS NOT AN ANNOUNCEMENT. sp-here says "you are here" in 600
+ // against 400, which a sighted reader gets for free and a screen reader
+ // is told nothing about — the tree reads as a flat list of links with no
+ // indication of which one you are on. aria-current is the one attribute
+ // that carries it.
+ if (here) a.setAttribute('aria-current', 'page')
const ico = el('span', 'sp-tree-ico')
ico.innerHTML = pageIcon(page.icon)
const label = document.createElement('span')
@@ -1047,7 +1054,9 @@ export class Editor {
const li = document.createElement('li')
const a = document.createElement('a')
a.href = `#p/${page.id}`
- a.className = 'sp-treelink sp-arch-row' + (page.id === s.pageId ? ' sp-here' : '')
+ const hereA = page.id === s.pageId
+ a.className = 'sp-treelink sp-arch-row' + (hereA ? ' sp-here' : '')
+ if (hereA) a.setAttribute('aria-current', 'page')
const ico = el('span', 'sp-tree-ico')
ico.innerHTML = pageIcon(page.icon)
const label = document.createElement('span')