Skip to content

fix: add keyboard focus trap and return focus to modals#27

Open
Odunsih1 wants to merge 3 commits into
akinloluwami:mainfrom
Odunsih1:fix/modal-focus-trap
Open

fix: add keyboard focus trap and return focus to modals#27
Odunsih1 wants to merge 3 commits into
akinloluwami:mainfrom
Odunsih1:fix/modal-focus-trap

Conversation

@Odunsih1
Copy link
Copy Markdown

@Odunsih1 Odunsih1 commented Apr 30, 2026

fix: add keyboard focus trap and return focus to modals
What this fixes
Modals lacked a proper keyboard focus trap, meaning Tab could escape the dialog and interact with elements behind it. Additionally, focus was not returned to the triggering element after a modal closed.
Changes

Added src/hooks/use-focus-trap.ts, a shared hook that handles:

Trapping Tab/Shift+Tab within the open dialog
Capturing the triggering element on open and returning focus to it on close

Applied the hook to all four modals:

NewCanvasDialog
DeleteConfirmDialog
EditorShortcutsModal
ImageCropModal

Accessibility impact

Tab and Shift+Tab now cycle only through focusable elements inside the open modal
Closing any modal (via Escape, Cancel, backdrop click, or confirm) returns focus to the element that opened it
Consistent behavior across all modals via a single reusable hook

Before:

Video.Project.1.mp4

After:

Video.Project.2.mp4

View in Codesmith
Need help on this PR? Tag @codesmith with what you need.

  • Let Codesmith autofix CI failures and bot reviews

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 30, 2026

@Odunsih1 is attempting to deploy a commit to the Akinkunmi Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 5 files

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.

1 participant