From b816203c0c69aea1a4876a8c21a8d44dcf5c19b4 Mon Sep 17 00:00:00 2001 From: Zaldimmar Date: Fri, 2 Oct 2026 14:33:09 -0500 Subject: [PATCH 1/3] Accessibility: reading and color blind modes, audit fixes, calendar window - Accessibility panel: the switch knob stays in its track; the panel follows its button in the Tab order and opens on its first switch. - Reading mode is the page as plain text: one column, no colors, pictures, cards or motion; descriptions stay in place. - Color blind mode (protanopia, deuteranopia, tritanopia, monochrome): palette swaps chosen by simulation, applied to code, data and CSS colors on public pages only. The newsletter uses the stored palette. - Audit fixes: focus not hidden by the header, focus on page change and in-page jumps, focus return for the menu, day list and people details, labelled admin fields and dialogs, keyboard map tiles, scrollable tables, and more. - Calendar asks /events for its six weeks only (?from=&to=); carousels take their 12 most recent past events (?past=12). Co-Authored-By: Claude Opus 5.5 --- docs/updating-data-in-code.md | 1 + index.html | 8 +- server/src/routes/content.js | 31 ++- src/components/AccessibilityPanel.tsx | 179 ++++++++++++++---- src/components/Banner.tsx | 2 +- src/components/ContentBlocks.tsx | 12 +- src/components/Footer.tsx | 6 +- src/components/Layout.tsx | 75 ++++++-- src/components/LegalText.tsx | 2 +- src/components/PageBackdrop.css | 6 +- src/components/PageBackdrop.tsx | 3 +- src/components/PageShell.css | 6 +- src/components/PageShell.tsx | 5 +- src/components/PeopleTiles.tsx | 2 + src/components/PostContents.tsx | 4 +- src/components/PrivacyNotice.tsx | 2 +- src/components/ScheduleBlock.tsx | 2 + src/components/VideoPlayer.tsx | 12 +- src/components/admin/DriveFiles.tsx | 2 + src/components/admin/MediaLibrary.tsx | 2 + src/components/admin/SectionNav.tsx | 18 +- src/components/admin/fields.tsx | 19 +- src/index.css | 138 ++++++++++++-- src/lib/api.ts | 23 ++- src/lib/color.ts | 108 ++++++++--- src/lib/eventData.ts | 17 +- src/lib/focus.ts | 24 +++ src/lib/motion.ts | 14 +- src/lib/newsletter.ts | 2 +- src/lib/useResource.ts | 11 +- src/pages/SitePage.tsx | 4 +- src/pages/admin/AdminClips.tsx | 1 + src/pages/admin/AdminFeedback.tsx | 2 + src/pages/admin/AdminMedia.tsx | 2 + src/pages/admin/AdminNewsletter.tsx | 7 +- src/pages/admin/AdminPanel.tsx | 1 + src/pages/admin/EntityList.tsx | 1 + src/pages/sections/EventCalendar.tsx | 117 ++++++++---- src/pages/sections/EventList-Cards.tsx | 21 +- src/pages/sections/FeedbackForm.tsx | 17 +- src/pages/sections/OrgList-Map.tsx | 26 ++- src/pages/sections/RequestForm.tsx | 16 +- src/pages/sections/home/HeroStage.tsx | 6 +- .../sections/home/NextEventCountdown.tsx | 6 +- src/pages/sections/home/StatsBand.tsx | 5 +- 45 files changed, 760 insertions(+), 208 deletions(-) create mode 100644 src/lib/focus.ts diff --git a/docs/updating-data-in-code.md b/docs/updating-data-in-code.md index 2866be8..a186be5 100644 --- a/docs/updating-data-in-code.md +++ b/docs/updating-data-in-code.md @@ -279,6 +279,7 @@ The numbers band's "Number Source" dropdown works the same way: | The icons a Front page "Find your way in" path can pick | `src/data/pathIcons.ts` (keys and labels) **and** `ICONS` in `src/pages/sections/home/Pathfinder.tsx` (the Phosphor icon for each key) | Add a line to both. A path saved with an emoji from before the list shows it as it is. | | A page section's accent color | `BRAND` and `ACCENTS` in `src/lib/color.ts` | Pages pick from these (`accent: ACCENTS.green`); add a color there, not a hex in a page. Each is readable as text on white and the tints. | | The palette (the 16-color grid the theme is drawn from) | `PALETTE` in `src/lib/color.ts` | Four families, a column each. `PALETTE_LIGHT` / `PALETTE_DARK` are the fills things colored by data use (a person's initials tile, `paletteFill`); the page background's layers (how many circles, their sizes and parallax speeds) are `LAYERS` in `src/components/PageBackdrop.tsx` and its shades are in `PageBackdrop.css`; the admin home's two alternating group colors are `BLOCK_COLORS` in `src/pages/admin/AdminHome.tsx`. | +| The accessibility panel's choices (bottom right of every public page) | `SETTINGS` in `src/components/AccessibilityPanel.tsx`; the color blind modes are `VISIONS` and `SWAPS` in `src/lib/color.ts` | Each choice is an attribute on `` styled in `src/index.css`, and `index.html` sets it again before the first paint, so a new one goes in all three. A color blind mode swaps palette families (`SWAPS`, picked by simulating each type: see the comment there) in code, in data colors as they load (`src/lib/api.ts`, never under /admin) and in CSS (the `--green-*` variables in `src/index.css`); a hex from the green family in a component should be one of those variables. Something saved or sent (the newsletter's colors) uses `STORED_PALETTE`, which is never swapped. | | Privacy Policy and Terms wording | `src/pages/Privacy.tsx`, `src/pages/Terms.tsx` | The `PARTS` list, and `LAST_UPDATED` whenever the wording changes. The Privacy page must stay true of the code: what the feedback form stores, what the browser keeps, which embeds wait for a click. | | Event type labels and plurals (public site) | `src/lib/eventTypes.ts` | Also the order of the type filter chips. | | Event and person role labels (public site) | `ROLE_LABEL` in `src/pages/EventDetail.tsx` and `src/pages/PersonDetail.tsx` | | diff --git a/index.html b/index.html index 50ffe59..b395471 100644 --- a/index.html +++ b/index.html @@ -17,8 +17,14 @@ document.documentElement.dataset.theme = t === "dark" || t === "light" ? t : matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light"; // The accessibility panel's choices (AccessibilityPanel.tsx). + // Reading and color blind modes are for the public pages: the + // admin edits colors and layout, which they would hide. if (localStorage.getItem("site-font") === "dyslexic") document.documentElement.dataset.font = "dyslexic"; - if (localStorage.getItem("site-reading") === "on") document.documentElement.dataset.reading = "on"; + if (!location.pathname.startsWith("/admin")) { + if (localStorage.getItem("site-reading") === "on") document.documentElement.dataset.reading = "on"; + var v = localStorage.getItem("site-vision"); + if (/^(protanopia|deuteranopia|tritanopia|monochrome)$/.test(v || "")) document.documentElement.dataset.vision = v; + } } catch (e) {} diff --git a/server/src/routes/content.js b/server/src/routes/content.js index 6d65d0e..bbe9bb7 100644 --- a/server/src/routes/content.js +++ b/server/src/routes/content.js @@ -463,7 +463,7 @@ content.get("/events", (c) => { // Optional filters, each narrowing the list (src/lib/eventData.ts): // ?scope=national ?host= ?status=upcoming - // ?type=class,workshop + // ?type=class,workshop ?from=&to= (a date window) ?past=12 const where = [`is_published = 1`, `is_listed = 1`]; const params = []; const scope = c.req.query("scope"); @@ -477,11 +477,38 @@ content.get("/events", (c) => { if (status) where.push(`effective_status = ?`), params.push(status); const types = (c.req.query("type") ?? "").split(",").filter(Boolean).slice(0, 20); if (types.length) where.push(`event_type IN (${marks(types.length)})`), params.push(...types); + // ?from=2026-10-01&to=2026-11-07: only events with a day in that + // window (the calendar's six weeks), plus the undated ones it + // counts. Either end may be left off. A series with no end date + // runs on, so it stays in every window after its start. + const day = (name) => { + const value = c.req.query(name); + return /^\d{4}-\d{2}-\d{2}$/.test(value ?? "") ? value : null; + }; + const from = day("from"); + const to = day("to"); + if (from || to) { + const dated = []; + if (to) dated.push(`starts_on <= ?`), params.push(to); + if (from) { + dated.push(`COALESCE(ends_on, CASE WHEN is_series = 1 THEN '9999-12-31' ELSE starts_on END) >= ?`); + params.push(from); + } + where.push(`(starts_on IS NULL OR (${dated.join(" AND ")}))`); + } - const rows = db + let rows = db .prepare(`SELECT * FROM v_events WHERE ${where.join(" AND ")} ORDER BY ${EVENT_ORDER}`) .all(...params); + // ?past=12: only the 12 most recent past events (a carousel's way + // back), before their links, cards and hosts are loaded. + const past = Number.parseInt(c.req.query("past") ?? "", 10); + if (past >= 0) { + let keep = rows.filter((row) => row.effective_status === "past").length - past; + rows = rows.filter((row) => row.effective_status !== "past" || keep-- <= 0); + } + const ids = rows.map((row) => row.id); const links = loadLinks(db, "event", ids); const cards = loadBlocks(db, "event", ids, "card"); diff --git a/src/components/AccessibilityPanel.tsx b/src/components/AccessibilityPanel.tsx index faf5ecc..9f25f16 100644 --- a/src/components/AccessibilityPanel.tsx +++ b/src/components/AccessibilityPanel.tsx @@ -2,28 +2,42 @@ ACCESSIBILITY PANEL A button fixed to the bottom right of every public page, opening - two switches that change how the whole site reads: + two switches and a choice that change how the whole site reads: Dyslexia-friendly font every typeface becomes OpenDyslexic (self-hosted, index.css) - Reading mode the design steps back: no background - circles, motion or shadows, one column, - larger text and plain underlined links, - the same content throughout + Reading mode the page as plain text: one column of + ink on white, no colors, pictures, + cards or motion; a picture's + description stays in its place + Color blind mode the palette swapped so its colors stay + apart for that type of color blindness, + or grays (color.ts, VISIONS) - Each is a data attribute on (data-font, data-reading) that - index.css styles, saved in this browser (site-font, site-reading) - and set again before the first paint by index.html, so a page - never flashes the other look. Blocked storage just means the - choice lasts until the tab closes. + Each is a data attribute on (data-font, data-reading, + data-vision) that index.css styles, saved in this browser + (site-font, site-reading, site-vision) and set again before the + first paint by index.html, so a page never flashes the other + look. A color blind mode reloads the page, since colors set from + code and data are swapped as they load. Blocked storage just + means the choice lasts until the tab closes. - The panel closes on Escape, on the button again, or a click + Reading and color blind modes belong to the public pages, which + are the only ones with this panel: it sets them when they mount + and clears them when the admin takes over (index.html leaves them + off there too), since the admin edits the colors and layout they + would hide. The font follows the visitor everywhere. + + The panel opens on its first switch, comes after its button in + the Tab order, closes on Escape, on the button again, or a click anywhere else, and gives focus back to the button. ═══════════════════════════════════════════════════════════════ */ import { PersonArmsSpread, X } from '@phosphor-icons/react' import { useEffect, useId, useRef, useState } from 'react' +import { VISIONS } from '../lib/color.ts' + /* A setting: its attribute, storage key, the value that turns it on, and its words. */ const SETTINGS = [ @@ -39,35 +53,89 @@ const SETTINGS = [ key: 'site-reading', on: 'on', label: 'Reading mode', - help: 'A plain, single column with larger text and no motion.', + help: 'The page as plain text: one column, larger type, no colors, pictures or motion.', }, ] as const type Setting = (typeof SETTINGS)[number] -const isOn = (setting: Setting) => document.documentElement.dataset[setting.attribute] === setting.on - -function apply(setting: Setting, on: boolean) { - const root = document.documentElement - if (on) root.dataset[setting.attribute] = setting.on - else delete root.dataset[setting.attribute] +/* The saved choice, or the page's own where storage is blocked. */ +function saved(attribute: string, key: string): string | null { try { - if (on) localStorage.setItem(setting.key, setting.on) - else localStorage.removeItem(setting.key) + return localStorage.getItem(key) + } catch { + return document.documentElement.dataset[attribute] ?? null + } +} + +const isOn = (setting: Setting) => saved(setting.attribute, setting.key) === setting.on +const PUBLIC_ONLY = [ + { attribute: 'reading', key: 'site-reading' }, + { attribute: 'vision', key: 'site-vision' }, +] + +/* Sets (or, given null, clears) an attribute and its saved copy. */ +function apply(attribute: string, key: string, value: string | null) { + const root = document.documentElement + if (value) root.dataset[attribute] = value + else delete root.dataset[attribute] + try { + if (value) localStorage.setItem(key, value) + else localStorage.removeItem(key) } catch { // Storage blocked: the choice holds for this page view. } } +/* Reading mode hides pictures, video and maps; their descriptions + (alt, title, aria-label) go on the parent as data-reading-alt, + which index.css shows in their place. An attribute rather than a + new element, so React's own nodes are left alone. */ +const DESCRIBED = 'main img[alt]:not([alt=""]), main iframe[title], main video[aria-label]' + +function describeMedia() { + for (const el of document.querySelectorAll(DESCRIBED)) { + const words = el.getAttribute('alt') ?? el.getAttribute('title') ?? el.getAttribute('aria-label') + const kind = el.tagName === 'IMG' ? 'Image' : 'Video' + el.parentElement?.setAttribute('data-reading-alt', `${kind}: ${words}`) + } +} + +function useMediaDescriptions(on: boolean) { + useEffect(() => { + if (!on) return undefined + describeMedia() + const observer = new MutationObserver(describeMedia) + observer.observe(document.body, { childList: true, subtree: true }) + return () => observer.disconnect() + }, [on]) +} + export default function AccessibilityPanel() { const [open, setOpen] = useState(false) const [state, setState] = useState(() => Object.fromEntries(SETTINGS.map((s) => [s.key, isOn(s)]))) + const [vision, setVision] = useState(() => saved('vision', 'site-vision') ?? '') const rootRef = useRef(null) const buttonRef = useRef(null) + const firstRef = useRef(null) const panelId = useId() + useMediaDescriptions(state['site-reading']) + + useEffect(() => { + const root = document.documentElement + for (const { attribute, key } of PUBLIC_ONLY) { + const value = saved(attribute, key) + if (value) root.dataset[attribute] = value + } + return () => { + for (const { attribute } of PUBLIC_ONLY) delete root.dataset[attribute] + } + }, []) + useEffect(() => { if (!open) return undefined + firstRef.current?.focus() const close = () => { setOpen(false) buttonRef.current?.focus() @@ -88,18 +156,38 @@ export default function AccessibilityPanel() { const toggle = (setting: Setting) => { const next = !state[setting.key] - apply(setting, next) + apply(setting.attribute, setting.key, next ? setting.on : null) setState((current) => ({ ...current, [setting.key]: next })) } + const chooseVision = (value: string) => { + setVision(value) + apply('vision', 'site-vision', value || null) + window.location.reload() + } + return (
+ + + {/* After the button in the page, so Tab goes from it into the + panel; drawn above it. */} {open && (

Accessibility

@@ -117,25 +205,31 @@ export default function AccessibilityPanel() {
    - {SETTINGS.map((setting) => { + {SETTINGS.map((setting, i) => { const on = state[setting.key] const labelId = `${panelId}-${setting.attribute}` + const helpId = `${labelId}-help` return (
  • @@ -143,26 +237,35 @@ export default function AccessibilityPanel() { {setting.label} - {setting.help} + + {setting.help} +
  • ) })}
+ +
)} - -
) } diff --git a/src/components/Banner.tsx b/src/components/Banner.tsx index a0be933..a8fb404 100644 --- a/src/components/Banner.tsx +++ b/src/components/Banner.tsx @@ -25,7 +25,7 @@ export default function Banner() { if (!visible) return null; const linkClass = - "underline underline-offset-4 decoration-[#9cc47c] hover:text-white transition-colors"; + "underline underline-offset-4 decoration-[var(--green-2)] hover:text-white transition-colors"; return (
+

{text}

) case 'subheading': return ( -

+

{text}

) @@ -248,8 +245,9 @@ function Block({ block, accent, anchor }: { block: ContentBlock; accent: string; const width = Math.max(...rows.map((row) => row.length)) return ( // Wide tables scroll sideways inside their box on a phone - // rather than squeezing every column to a word. -
+ // rather than squeezing every column to a word. Focusable, so + // the arrow keys scroll it too (Safari won't on its own). +
diff --git a/src/components/Footer.tsx b/src/components/Footer.tsx index a291b87..4ec43b4 100644 --- a/src/components/Footer.tsx +++ b/src/components/Footer.tsx @@ -28,14 +28,14 @@ const Footer_Links = [ ]; const footerLinkClass = - "text-white/65 hover:text-[#9cc47c] text-sm transition-colors"; + "text-white/65 hover:text-[var(--green-2)] text-sm transition-colors"; // inline-block with a little height of its own, so a finger can hit it. const pageLinkClass = - "inline-block py-1 text-white/80 hover:text-[#9cc47c] text-sm font-semibold transition-colors"; + "inline-block py-1 text-white/80 hover:text-[var(--green-2)] text-sm font-semibold transition-colors"; const sectionLinkClass = - "inline-block py-1 text-white/65 hover:text-[#9cc47c] text-sm transition-colors"; + "inline-block py-1 text-white/65 hover:text-[var(--green-2)] text-sm transition-colors"; const headingClass = "text-white/90 text-sm font-semibold mb-4"; diff --git a/src/components/Layout.tsx b/src/components/Layout.tsx index e98b6b2..8bbb625 100644 --- a/src/components/Layout.tsx +++ b/src/components/Layout.tsx @@ -10,7 +10,7 @@ import PrivacyNotice from "./PrivacyNotice.tsx"; import PageBackdrop from "./PageBackdrop.tsx"; import AccessibilityPanel from "./AccessibilityPanel.tsx"; import ThemeToggle from "./ThemeToggle.tsx"; -import { scrollBehavior } from "../lib/motion.ts"; +import { jumpTo } from "../lib/focus.ts"; /* ── Right-side nav actions ──────────────────────────────── */ @@ -82,7 +82,12 @@ export default function Layout() { const [headerHeight, setHeaderHeight] = useState(72); const headerRef = useRef(null); const closeMenuRef = useRef(null); + const openMenuRef = useRef(null); + // The desktop dropdown Escape has shut, until the pointer or focus + // leaves it (hover and focus would otherwise hold it open). + const [dismissed, setDismissed] = useState(null); const location = useLocation(); + const lastPath = useRef(location.pathname); const sectionsOf = useNavSections(); @@ -98,7 +103,13 @@ export default function Layout() { closeMenuRef.current?.focus(); const onKey = (e: KeyboardEvent) => e.key === "Escape" && setMobileMenuOpen(false); window.addEventListener("keydown", onKey); - return () => window.removeEventListener("keydown", onKey); + return () => { + window.removeEventListener("keydown", onKey); + // Closed with Escape or Close, focus fell to the page with the + // menu: give it back to the menu button. A link that changed + // the page has already sent it to the new page (below). + if (document.activeElement === document.body) openMenuRef.current?.focus(); + }; }, [mobileMenuOpen]); // The header grows and shrinks: the banner can be dismissed, and @@ -115,27 +126,36 @@ export default function Layout() { return () => ro.disconnect(); }, []); + // On the root, so anything can read it: index.css keeps focused + // and jumped-to things clear of the header with it + // (scroll-padding-top), and PostContents offsets by it. + useEffect(() => { + const root = document.documentElement; + root.style.setProperty("--header-h", `${headerHeight}px`); + // The admin has no fixed header: nothing to stay clear of there. + return () => { + root.style.removeProperty("--header-h"); + }; + }, [headerHeight]); + // Router does not scroll on navigation. Go to top on a new page, // or to the anchor if the URL carries one (handles deep links too). + // A new page also takes focus to its content, as a page load would, + // so a screen reader starts there and Tab doesn't begin from a + // link that may be gone. useEffect(() => { - if (location.hash) { - const el = document.querySelector(location.hash); - if (el) { - el.scrollIntoView({ behavior: scrollBehavior() }); - return; - } - } + const newPage = lastPath.current !== location.pathname; + lastPath.current = location.pathname; + if (location.hash && jumpTo(decodeURIComponent(location.hash.slice(1)))) return; window.scrollTo({ top: 0 }); + if (newPage) document.getElementById("main")?.focus({ preventScroll: true }); }, [location.pathname, location.hash, location.key]); return ( // overflow-x-clip, not -hidden: hidden makes this div a scroll // container, and then nothing inside it can be position: sticky // (a blog post's contents column scrolled away with the page). -
+
{ const pageSections = page.path === "/" ? [] : sectionsOf(page.path); return ( -
+
{ + if (e.key !== "Escape" || pageSections.length === 0) return; + setDismissed(page.path); + e.currentTarget.querySelector("a")?.focus(); + }} + onMouseLeave={() => setDismissed(null)} + onBlur={(e) => { + if (!e.currentTarget.contains(e.relatedTarget as Node)) setDismissed(null); + }} + > `block text-base font-bold pb-1 border-b-2 transition-colors duration-200 ${ isActive - ? "text-white border-[#9cc47c]" + ? "text-white border-[var(--green-2)]" : "text-white/75 hover:text-white border-transparent" }` } @@ -194,10 +226,14 @@ export default function Layout() { // (:focus-visible): a click leaves focus on the // link, which held the menu open after the // pointer had gone. -
+
    {pageSections.map((section) => (
  • @@ -228,6 +264,7 @@ export default function Layout() {