Skip to content

fix(a11y): accessible modal dismissal (Escape, focus trap, focus return)#4

Open
ocheeluma wants to merge 1 commit into
mainfrom
fix/483-modal-dismissal-accessibility
Open

fix(a11y): accessible modal dismissal (Escape, focus trap, focus return)#4
ocheeluma wants to merge 1 commit into
mainfrom
fix/483-modal-dismissal-accessibility

Conversation

@ocheeluma

Copy link
Copy Markdown
Owner

Closes AnnabelJoe#483

Changes

Both retire-modal.tsx and transfer-modal.tsx updated:

Escape key dismissal

  • Added useEffect with document.addEventListener('keydown') — pressing Escape calls onClose().

Focus trap

  • onKeyDown handler on the dialog <div> intercepts Tab/Shift+Tab.
  • Queries all focusable descendants and wraps Tab from last → first and Shift+Tab from first → last.

Focus return

  • document.activeElement is captured in a ref on mount (before focus moves into the dialog).
  • On unmount (cleanup of first useEffect), focus is restored to the captured element.

Auto-focus

  • Dialog container has tabIndex={-1} and receives .focus() on mount so keyboard position is immediately inside the modal.

Close button labels

  • Updated from generic "Close" to "Close retire certificate dialog" / "Close transfer certificate dialog" for unambiguous screen reader context.

Testing

  • Open modal → Tab through fields → confirm focus stays inside.
  • Press Escape → confirm modal closes and focus returns to the button that opened it.
  • Screen reader: confirm close button announces dialog name.

…nnabelJoe#483)

- Escape key closes the modal via document keydown listener
- Focus trap: Tab/Shift+Tab cycle within dialog, never leaving it
- Focus auto-moves to dialog div on open (tabIndex=-1, outline-none)
- Focus returns to the triggering element on close (captured via
  document.activeElement in useEffect mount/unmount)
- Close button aria-label updated to be dialog-specific (e.g.
  'Close retire certificate dialog') for screen reader context
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Audit modal dismissal mechanisms for accessibility

1 participant