fix: add keyboard focus trap and return focus to modals#27
Open
Odunsih1 wants to merge 3 commits into
Open
Conversation
|
@Odunsih1 is attempting to deploy a commit to the Akinkunmi Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Need help on this PR? Tag
@codesmithwith what you need.