Commit 1e0a924
authored
fix(admin/spa): drop redundant abort guard and add Modal a11y (#650)
## Summary
Two follow-ups from the
[#649](#649) review that were
intentionally deferred to keep that PR focused on the functional bugs.
**Stacked on `feat/admin-dashboard-spa`** (#649). Once #649 merges, this
rebases cleanly onto `main`.
### 1. `useApi.ts` — drop the redundant abort guard
The `catch` handler had two checks back-to-back:
```ts
if (cancelled) return;
if (ctrl.signal.aborted) return; // ← unreachable
```
The cleanup function sets `cancelled = true` *before* calling
`ctrl.abort()`, so any abort path is already covered by the first check.
Dropped the second guard and recorded *why* one check is enough in a
comment.
### 2. `Modal.tsx` — full WAI-ARIA dialog contract + focus trap
Added:
- `role="dialog"`, `aria-modal="true"`, `aria-labelledby` on the dialog
root (uses `useId()` for the title id).
- Focus management:
- On open: store the previously-focused element, focus the first
focusable inside the dialog.
- Tab / Shift+Tab cycle within the dialog instead of escaping to the
page underneath.
- On close: restore focus to whoever opened the dialog (skipped if that
element was unmounted by the dialog action — e.g. the dialog deleted the
row whose button opened it).
- Empty-dialog fallback focuses the dialog container itself with
`tabindex=-1`.
Vanilla DOM implementation — `focus-trap-react` / `react-focus-lock`
would have been 5–7 KB gzip for what is a ~40 line solution.
**Bundle delta**: +0.4 KB gzip (60.23 → 60.59 KB JS, 14.55 → 14.57 KB
CSS).
## Test plan
- [x] `cd web/admin && npm install && npm run build`
- [x] `cd web/admin && npm run lint` — `tsc --strict`
- [x] `go build ./...`
- [ ] Manual smoke (after #649 merges and the dashboard is visitable):
- Open Create Table / Delete Table dialog → focus lands inside the
dialog.
- Tab past the last button → wraps back to the close button.
- Shift+Tab from the close button → wraps to the last form field.
- Escape closes (when not `busy`) and focus returns to the trigger
button.
- Screen reader announces the dialog name from the title text.2 files changed
Lines changed: 114 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
18 | 28 | | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
19 | 66 | | |
20 | 67 | | |
21 | 68 | | |
22 | | - | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
23 | 92 | | |
24 | 93 | | |
25 | 94 | | |
| |||
33 | 102 | | |
34 | 103 | | |
35 | 104 | | |
36 | | - | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
37 | 112 | | |
38 | | - | |
| 113 | + | |
39 | 114 | | |
40 | 115 | | |
41 | 116 | | |
| |||
51 | 126 | | |
52 | 127 | | |
53 | 128 | | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
47 | 50 | | |
48 | | - | |
49 | 51 | | |
50 | 52 | | |
51 | 53 | | |
| |||
0 commit comments