Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: make Character Sheet name editing semantic and keyboard accessible (#2391)

Adam Eivy1f0b3f0ec007
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index a31c1728f1..ef56447715 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -10,6 +10,8 @@
- **The reference-audio waveform is now keyboard-operable and two hand-rolled modals gained real dialog semantics.** The Songs "reference analysis" waveform scrubber was a mouse-only `<div onClick>` (`role="presentation"`) — keyboard and screen-reader users could not seek at all. It is now a proper `role="slider"` with `aria-valuemin/max/now/valuetext`, focusable, and scrubbable with the arrow keys (±1s, ±5s with Shift) plus Home/End (WCAG 2.1.1). Separately, the CyberCity photo-mode "postcard preview" overlay and the Catalog "pick from media gallery" picker were hand-rolled `fixed inset-0` backdrops with no `role="dialog"`, no `aria-modal`, no Escape-to-close, and no focus trap; both now render through the shared `Modal` (focus trap + Esc stack + labelled dialog), with the postcard preview portaled so it escapes the WebGL HUD's stacking/pointer-events context.
+- **[issue-2391] The Character Sheet name is now editable by keyboard and screen reader.** Editing the hero's name used to hang off a non-semantic `<h2 onClick>` — invisible to the keyboard (not focusable, Enter/Space did nothing) and unlabelled for assistive tech. The name is now a real labelled `<button>` (`aria-label="Edit character name (currently …)"`, `type="button"` so it can't submit any wrapping form) that reveals an `aria-label`ed text input; the input commits on **Enter**, cancels and restores the original name on **Escape** (both `preventDefault`ed to avoid accidental form behavior), and still saves on blur — resolved exactly once via a re-entrancy guard so the Enter/Escape-then-blur pair can't double-save. The 2xl-bold hover-accent visual treatment is unchanged, and new accessibility-focused component tests cover the labelled control plus the Enter/Escape flows.
+
- **Modals and drawers now trap and restore keyboard focus, and toasts are announced to screen readers.** Opening any shared `Modal` or `Drawer` (which back the great majority of the app's dialogs, config drawers, and lightboxes) now moves focus into the dialog, keeps Tab/Shift+Tab cycling inside it instead of leaking to the page behind, and returns focus to the control that opened it on close (WCAG 2.4.3 / 2.1.2) — implemented once in a reusable `useFocusTrap` hook. The toast stack is now a labelled ARIA notification region: default toasts announce politely (`role="status"`) and error toasts assertively (`role="alert"`), with the decorative status glyphs hidden from assistive tech, so screen-reader users hear notifications (including error toasts) as they arrive.
## AI Providers
diff --git a/client/src/pages/CharacterSheet.a11y.test.jsx b/client/src/pages/CharacterSheet.a11y.test.jsx
new file mode 100644
index 0000000000..6494480f07
--- /dev/null
+++ b/client/src/pages/CharacterSheet.a11y.test.jsx
@@ -0,0 +1,104 @@
+import { describe, it, expect, vi, beforeEach } from 'vitest';
+import { render, screen, fireEvent, waitFor } from '@testing-library/react';
+import { MemoryRouter } from 'react-router-dom';
+
+// Accessibility-focused coverage for the Character Sheet name-edit control
+// (issue #2391): the view-mode trigger must be a labeled, keyboard-operable
+// button, and the edit input must support Enter (commit) and Escape (cancel)
+// without accidental form submission.
+
+const get = vi.fn();
+const put = vi.fn();
+
+vi.mock('../services/api', () => ({
+ default: { get: (...a) => get(...a), post: vi.fn(), put: (...a) => put(...a) },
+ generateAvatar: vi.fn(() => Promise.resolve({})),
+}));
+
+vi.mock('../services/socket', () => ({
+ default: { on: vi.fn(), off: vi.fn(), emit: vi.fn() },
+}));
+
+vi.mock('../components/ui/Toast', () => ({
+ default: { error: vi.fn(), success: vi.fn(), info: vi.fn() },
+}));
+
+import CharacterSheet from './CharacterSheet';
+
+const CHAR = {
+ name: 'Aragorn',
+ class: 'Ranger',
+ level: 5,
+ hp: 40,
+ maxHp: 40,
+ xp: 6500,
+ avatarPath: null,
+ events: [],
+};
+
+const renderSheet = () => render(
+ <MemoryRouter>
+ <CharacterSheet />
+ </MemoryRouter>,
+);
+
+beforeEach(() => {
+ vi.clearAllMocks();
+ get.mockResolvedValue({ ...CHAR });
+ put.mockImplementation((_path, body) => Promise.resolve({ ...CHAR, ...body }));
+});
+
+const findNameTrigger = () =>
+ screen.findByRole('button', { name: /edit character name/i });
+
+describe('CharacterSheet name editing accessibility', () => {
+ it('exposes the name as a labeled, keyboard-focusable button', async () => {
+ renderSheet();
+ const trigger = await findNameTrigger();
+ // A real <button> is focusable and keyboard-operable by default.
+ expect(trigger.tagName).toBe('BUTTON');
+ expect(trigger).toHaveAttribute('type', 'button');
+ expect(trigger).toHaveTextContent('Aragorn');
+ });
+
+ it('reveals a labeled input when the trigger is activated', async () => {
+ renderSheet();
+ const trigger = await findNameTrigger();
+ fireEvent.click(trigger);
+ const input = screen.getByLabelText('Character name');
+ expect(input).toHaveValue('Aragorn');
+ });
+
+ it('commits the edit on Enter without accidental form submission', async () => {
+ renderSheet();
+ fireEvent.click(await findNameTrigger());
+ const input = screen.getByLabelText('Character name');
+ fireEvent.change(input, { target: { value: 'Strider' } });
+
+ fireEvent.keyDown(input, { key: 'Enter' });
+
+ await waitFor(() => expect(put).toHaveBeenCalledWith('/character', { name: 'Strider' }));
+ // Back to the button view with the new name.
+ await waitFor(() =>
+ expect(screen.getByRole('button', { name: /edit character name/i }))
+ .toHaveTextContent('Strider'),
+ );
+ });
+
+ it('cancels the edit on Escape and restores the original name', async () => {
+ renderSheet();
+ fireEvent.click(await findNameTrigger());
+ const input = screen.getByLabelText('Character name');
+ fireEvent.change(input, { target: { value: 'Throwaway' } });
+
+ // Escape resolves the edit without saving and restores the original name.
+ fireEvent.keyDown(input, { key: 'Escape' });
+
+ // No save fired, and the original name is shown again.
+ await waitFor(() =>
+ expect(screen.getByRole('button', { name: /edit character name/i }))
+ .toHaveTextContent('Aragorn'),
+ );
+ expect(put).not.toHaveBeenCalled();
+ });
+});
diff --git a/client/src/pages/CharacterSheet.jsx b/client/src/pages/CharacterSheet.jsx
index 1dfabd8593..bf7e637e34 100644
--- a/client/src/pages/CharacterSheet.jsx
+++ b/client/src/pages/CharacterSheet.jsx
@@ -64,6 +64,10 @@ export default function CharacterSheet() {
const [diffusionProgress, setDiffusionProgress] = useState(null);
const generatingRef = useRef(false);
const generationIdRef = useRef(null);
+ // Guards the name edit against a double-commit: Enter/Escape resolve the edit
+ // and also blur the input, so both the key handler and the blur handler fire.
+ // Whichever runs first flips this false; the other becomes a no-op.
+ const nameEditingRef = useRef(false);
// Form states
const [dmgDice, setDmgDice] = useState('1d6');
@@ -189,14 +193,40 @@ export default function CharacterSheet() {
}
};
- const handleNameSave = async () => {
+ const startNameEdit = () => {
+ nameEditingRef.current = true;
+ setNameVal(char.name || '');
+ setEditingName(true);
+ };
+
+ // Resolve an in-progress name edit exactly once. `cancel` discards the edit
+ // and restores the persisted name; otherwise the trimmed value is saved.
+ const finishNameEdit = async (cancel) => {
+ if (!nameEditingRef.current) return;
+ nameEditingRef.current = false;
+ setEditingName(false);
+ if (cancel) {
+ setNameVal(char.name || '');
+ return;
+ }
try {
- if (nameVal.trim() && nameVal !== char.name) {
+ if (nameVal.trim() && nameVal.trim() !== char.name) {
const data = await charPut({ name: nameVal.trim() });
setChar(data);
}
} catch (err) { toast.error(err.message || 'Failed to save name'); }
- setEditingName(false);
+ };
+
+ // Enter commits, Escape cancels. preventDefault keeps Enter from triggering
+ // any accidental form submission.
+ const handleNameKeyDown = (e) => {
+ if (e.key === 'Enter') {
+ e.preventDefault();
+ finishNameEdit(false);
+ } else if (e.key === 'Escape') {
+ e.preventDefault();
+ finishNameEdit(true);
+ }
};
const handleClassSave = async () => {
@@ -329,20 +359,22 @@ export default function CharacterSheet() {
{editingName ? (
<input
autoFocus
+ aria-label="Character name"
value={nameVal}
onChange={e => setNameVal(e.target.value)}
- onBlur={handleNameSave}
- onKeyDown={e => e.key === 'Enter' && handleNameSave()}
+ onBlur={() => finishNameEdit(false)}
+ onKeyDown={handleNameKeyDown}
className="bg-port-bg border border-port-border rounded px-2 py-1 text-2xl font-bold text-white w-full max-w-xs"
/>
) : (
- <h2
- onClick={() => setEditingName(true)}
- className="text-2xl font-bold text-white cursor-pointer hover:text-port-accent transition-colors truncate"
- title="Click to edit name"
+ <button
+ type="button"
+ onClick={startNameEdit}
+ aria-label={`Edit character name (currently ${char.name || 'Unnamed Hero'})`}
+ className="text-2xl font-bold text-white cursor-pointer hover:text-port-accent transition-colors truncate text-left bg-transparent border-0 p-0"
>
{char.name || 'Unnamed Hero'}
- </h2>
+ </button>
)}
</div>
<div className="flex items-center gap-2">