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 <noreply@anthropic.com>
This commit is contained in:
parent
d067c02d33
commit
b816203c0c
45 changed files with 760 additions and 208 deletions
|
|
@ -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 <html> (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 <html> (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 <html> 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 <html> 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<HTMLDivElement>(null)
|
||||
const buttonRef = useRef<HTMLButtonElement>(null)
|
||||
const firstRef = useRef<HTMLButtonElement>(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 (
|
||||
<div ref={rootRef} className="fixed right-4 bottom-4 z-50 print:hidden">
|
||||
<button
|
||||
ref={buttonRef}
|
||||
type="button"
|
||||
onClick={() => setOpen((value) => !value)}
|
||||
aria-expanded={open}
|
||||
aria-controls={open ? panelId : undefined}
|
||||
aria-label="Accessibility options"
|
||||
className="btn flex h-12 w-12 items-center justify-center bg-action text-white shadow-lg transition-colors hover:bg-action-hover"
|
||||
>
|
||||
<PersonArmsSpread size={26} weight="bold" aria-hidden="true" />
|
||||
</button>
|
||||
|
||||
{/* After the button in the page, so Tab goes from it into the
|
||||
panel; drawn above it. */}
|
||||
{open && (
|
||||
<div
|
||||
id={panelId}
|
||||
role="region"
|
||||
aria-label="Accessibility"
|
||||
className="absolute right-0 bottom-full mb-3 w-[min(20rem,calc(100vw-2rem))] border border-brand/20 bg-raised p-4 shadow-xl"
|
||||
className="reading-solid absolute right-0 bottom-full mb-3 w-[min(20rem,calc(100vw-2rem))] border border-brand/20 bg-raised p-4 shadow-xl"
|
||||
>
|
||||
<div className="flex items-center justify-between gap-4">
|
||||
<h2 className="font-display text-base font-bold text-ink">Accessibility</h2>
|
||||
|
|
@ -117,25 +205,31 @@ export default function AccessibilityPanel() {
|
|||
</div>
|
||||
|
||||
<ul className="mt-3 space-y-3">
|
||||
{SETTINGS.map((setting) => {
|
||||
{SETTINGS.map((setting, i) => {
|
||||
const on = state[setting.key]
|
||||
const labelId = `${panelId}-${setting.attribute}`
|
||||
const helpId = `${labelId}-help`
|
||||
return (
|
||||
<li key={setting.key} className="flex items-start gap-3">
|
||||
<button
|
||||
ref={i === 0 ? firstRef : undefined}
|
||||
type="button"
|
||||
role="switch"
|
||||
aria-checked={on}
|
||||
aria-labelledby={labelId}
|
||||
aria-describedby={helpId}
|
||||
onClick={() => toggle(setting)}
|
||||
className={`relative mt-0.5 h-6 w-11 shrink-0 rounded-full border-2 transition-colors ${
|
||||
on ? 'border-action bg-action' : 'border-muted/50 bg-surface'
|
||||
}`}
|
||||
>
|
||||
{/* Pinned to the left edge: without it the knob
|
||||
starts from the button's centered content and
|
||||
slides out of the track when switched on. */}
|
||||
<span
|
||||
aria-hidden="true"
|
||||
className={`absolute top-0.5 h-4 w-4 rounded-full transition-transform ${
|
||||
on ? 'translate-x-5 bg-white' : 'translate-x-0.5 bg-muted'
|
||||
className={`absolute top-0.5 left-0.5 h-4 w-4 rounded-full transition-transform ${
|
||||
on ? 'translate-x-5 bg-white' : 'translate-x-0 bg-muted'
|
||||
}`}
|
||||
/>
|
||||
</button>
|
||||
|
|
@ -143,26 +237,35 @@ export default function AccessibilityPanel() {
|
|||
<span id={labelId} className="block font-semibold text-ink">
|
||||
{setting.label}
|
||||
</span>
|
||||
<span className="block text-sm text-muted">{setting.help}</span>
|
||||
<span id={helpId} className="block text-sm text-muted">
|
||||
{setting.help}
|
||||
</span>
|
||||
</span>
|
||||
</li>
|
||||
)
|
||||
})}
|
||||
</ul>
|
||||
|
||||
<label className="mt-4 block">
|
||||
<span className="block font-semibold text-ink">Color blind mode</span>
|
||||
<span className="block text-sm text-muted">
|
||||
Colors chosen to stay apart for your type. Reloads the page.
|
||||
</span>
|
||||
<select
|
||||
value={vision}
|
||||
onChange={(event) => chooseVision(event.target.value)}
|
||||
className="mt-2 w-full border border-muted/50 bg-surface px-3 py-2 text-sm text-ink"
|
||||
>
|
||||
<option value="">Off</option>
|
||||
{VISIONS.map((option) => (
|
||||
<option key={option.id} value={option.id}>
|
||||
{option.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<button
|
||||
ref={buttonRef}
|
||||
type="button"
|
||||
onClick={() => setOpen((value) => !value)}
|
||||
aria-expanded={open}
|
||||
aria-controls={open ? panelId : undefined}
|
||||
aria-label="Accessibility options"
|
||||
className="btn flex h-12 w-12 items-center justify-center bg-action text-white shadow-lg transition-colors hover:bg-action-hover"
|
||||
>
|
||||
<PersonArmsSpread size={26} weight="bold" aria-hidden="true" />
|
||||
</button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue