Appearance
ADR-2544: Shared Reactive Focus Containment and Global Reduced-Motion Tokens
- Status: Accepted
- Date: 2026-11-19
- Authors: @fderuiter
- Deciders: @fderuiter
- Requirements: PRD-CRF-015 (WCAG 2.1 AA keyboard focus containment and accessibility auditing)
1. Context & Problem Statement
Modal dialogs, slide-over drawers, and tab bars across the clinician workspace (apps/web), the participant portal (apps/subject-portal), and the shared design system (packages/ui) previously relied on fragmented focus-management helpers: a partial Vue composable in apps/web/src/composables/useFocusTrap.js, an imperative helper in apps/subject-portal/src/components/focus-trap.js, and inline keydown listeners in individual components. As a result, several dialogs and drawers lacked Tab/Shift+Tab focus wrapping or trigger restoration, offscreen persistent drawers remained reachable in the tab order when closed, participant portal tab navigation tracked only four of its six views imperatively, and continuous pulse/slide animations lacked a shared prefers-reduced-motion: reduce baseline.
2. Decision Drivers & Constraints
- WCAG 2.1 AA Compliance: Keyboard users and assistive technologies require deterministic focus containment inside active
role="dialog"/role="alertdialog"overlays, focus restoration on dismissal, inert offscreen drawers, and roving-tabindex navigation across all six participant portal tabs. - 21 CFR Part 11 & Mandatory Lock Guardrails: Mandatory security PIN lock dialogs (
PinSetupModal,PinUnlockModal) must contain focus while blockingEscapedismissal, whereas electronic signature and step-up re-authentication modals must immediately wipe typed credentials when dismissed viaEscape. - Single Shared UI Source: Per repository architecture guidelines, shared UI primitives, composables, and design tokens belong in
packages/uirather than duplicated per-application copies. - Vestibular Accessibility: Users with
prefers-reduced-motion: reduceenabled must have decorative infinite pulse animations halted and slide/fade transitions collapsed without hiding semantic status indicators.
3. Options Considered
Option 1: Rewrite All Overlays onto Native HTML <dialog> Elements
- Overview: Replace every existing
.vuemodal and drawer layout acrosspackages/ui,apps/web, andapps/subject-portalwith<dialog>andshowModal(). - Pros:
- ✅ Browser-managed top-layer rendering.
- Cons:
- ❌ High visual regression blast radius across 46 clinical modals, multi-step consoles, and slide-over drawers, plus inconsistent
jsdombehavior in existing synchronous unit test suites.
- ❌ High visual regression blast radius across 46 clinical modals, multi-step consoles, and slide-over drawers, plus inconsistent
Option 2: Centralize Reactive useFocusTrap and Reduced-Motion Rules in packages/ui (Selected)
- Overview: Implement a shared reactive
useFocusTrap(with stacked-overlay coordination,escapeDeactivates,onEscape,initialFocus, andrestoreFocus) anduseEscapeCloseinpackages/ui, wire all modal/drawer views acrosspackages/ui,apps/subject-portal, andapps/webto it, drive all six participant portal tabs reactively fromroutes.js+ui.currentView, and add a global@media (prefers-reduced-motion: reduce)rule inpackages/ui/tokens.css. - Pros:
- ✅ Eliminates duplicated focus-trap utilities across applications while preserving existing layout markup and styling.
- ✅ Handles nested modal/drawer stacks deterministically via a shared active trap stack and excludes
[inert]/ hidden subtrees. - ✅ Enforces reduced-motion rules workspace-wide from the shared design-token stylesheet.
- Cons:
- ❌ Persistent offscreen drawers that stay mounted in the DOM must explicitly bind
inertandvisibility: hiddenwhen closed.
- ❌ Persistent offscreen drawers that stay mounted in the DOM must explicitly bind
4. Decision Outcome
- Chosen Option: Option 2
- Justification: Centralizing
useFocusTrap,useEscapeClose, and reduced-motion token rules inpackages/uiachieves consistent WCAG 2.1 AA keyboard containment, focus restoration, and motion accessibility across all 46 overlays with minimal layout risk and full compatibility with 21 CFR Part 11 credential-clearing and PIN lock requirements.
5. Consequences & Trade-offs
- Positive Impact: One tested focus-containment implementation in
packages/uibackspackages/ui,apps/subject-portal, andapps/web;apps/subject-portal/src/components/focus-trap.jsis retired; all six participant portal tabs share a single reactive state source; and@media (prefers-reduced-motion: reduce)applies uniformly whereverpackages/ui/tokens.cssis imported. - Negative Impact / Technical Debt:
apps/webresolves"ui"against the builtpackages/ui/distbundle, so changes topackages/uicomposables require runningpnpm --filter ui buildbefore downstreamapps/webbuilds or tests. - Mitigation Strategy: Root
pnpm buildbuildsuibeforeweb, and unit/E2E accessibility suites inpackages/ui,apps/subject-portal, andapps/webverify focus containment,inertclosed drawers, six-tab roving tabindex, and reduced-motion rules.
6. Implementation & Verification
- Affected Repositories / Services:
packages/ui,apps/subject-portal,apps/web,docs/components/modal.md. - Verification Plan: Verified via Vitest unit/component suites (
packages/ui/tests/useFocusTrap.test.js,apps/subject-portal/tests/accessibility-focus-tabs.test.js,apps/web/tests/accessibility.test.js,apps/web/tests/components/ModalErrorAlertRetry.spec.ts), Playwright + axe-core WCAG 2.1 AA E2E tests (apps/subject-portal/tests/e2e/portal-accessibility.spec.js), andpnpm cadence check.