Skip to content

fix: add focus trap, keyboard handling, and aria-modal to PolicyConflictDialog (Closes #297) - #374

Merged
Lakes41 merged 1 commit into
Adamantine-guild:mainfrom
waterWang:fix/policy-conflict-focus-trap
Jul 29, 2026
Merged

fix: add focus trap, keyboard handling, and aria-modal to PolicyConflictDialog (Closes #297)#374
Lakes41 merged 1 commit into
Adamantine-guild:mainfrom
waterWang:fix/policy-conflict-focus-trap

Conversation

@waterWang

Copy link
Copy Markdown

Summary

Fixes the accessibility issues in PolicyConflictDialog as described in #297.

Changes

Component (components/ui/policy-conflict-dialog.tsx)

  • Added aria-modal="true" to the dialog container
  • Added ref onto the dialog container for focus trap targeting
  • Integrated the existing useFocusTrap hook from lib/hooks/use-focus-trap.ts:
    • Auto-focus on mount: Focus moves to the first focusable element (Cancel button) when the dialog opens
    • Focus trap: Tab/Shift+Tab cannot move focus to elements outside the dialog while it's open
    • Escape key: Pressing Escape calls onCancel and closes the dialog
    • Focus restoration: When the dialog closes, focus is restored to the element that had focus before the dialog opened

Tests

All 10 existing tests in test/policy-conflict-dialog-a11y.test.tsx pass, including the aria-modal="true" assertion.

Acceptance Criteria

  • Opening the dialog moves keyboard focus into it
  • Tab/Shift+Tab cannot move focus to elements outside the dialog while it's open
  • Pressing Escape calls onCancel and closes the dialog
  • Closing the dialog (via any button or Escape) restores focus to the triggering element
  • aria-modal="true" is present
  • All tests pass under npm test

Closes #297

…ictDialog

Adds accessible modal dialog behavior:
- aria-modal="true" attribute on the dialog container
- Focus trap using the existing useFocusTrap hook (Tab/Shift+Tab wrapping)
- Escape key handler that calls onCancel
- Auto-focus on mount and focus restoration on close
- Focus is trapped within the dialog while open

Closes Adamantine-guild#297
@waterWang
waterWang force-pushed the fix/policy-conflict-focus-trap branch from cb907d9 to b8d65b8 Compare July 29, 2026 11:58
@waterWang waterWang changed the title fix: add focus trap, keyboard handling, and aria-modal to PolicyConflictDialog [fj4WqyCCw3C5ShR1RfB7MoBPTpkRrBFYP1uT35g3MvT] fix: add focus trap, keyboard handling, and aria-modal to PolicyConflictDialog (Closes #297) Jul 29, 2026
@Lakes41
Lakes41 merged commit 0188654 into Adamantine-guild:main Jul 29, 2026
1 check passed
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.

Fix missing focus trap and keyboard handling in PolicyConflictDialog

2 participants