Skip to content

fix(z-modal): catch escaped focus in modal focus trap#658

Open
ada-workbackai wants to merge 1 commit intomasterfrom
workbackai/fix/wcag-2.4.3-modal-focus-trap-v2
Open

fix(z-modal): catch escaped focus in modal focus trap#658
ada-workbackai wants to merge 1 commit intomasterfrom
workbackai/fix/wcag-2.4.3-modal-focus-trap-v2

Conversation

@ada-workbackai
Copy link
Copy Markdown
Contributor

Summary

Fixes WCAG 2.4.3 (Focus Order) by catching escaped focus in the <z-modal> focus trap.

Issue: When tabbing through modal elements, focus escapes to the <z-modal> host element after the last interactive element, before cycling back into the modal inputs. This creates an unpredictable stop in the tab sequence that breaks focus order for keyboard and screen reader users.

Solution: Added a fallback in handleKeyDown that detects when the active element is not in the list of known focusable elements (i.e., focus has escaped to the host or dialog container) and redirects it back to the appropriate boundary element based on tab direction.

Test Plan

  • Built the component successfully without errors
  • Linting (eslint, prettier, stylelint) passes
  • Verified focus escape behavior on production (my.zanichelli.it login modal)
  • Focus trap logic handles escaped focus by redirecting to first/last focusable element

Evidence

View full audit details and evidence:
https://app.workback.ai/dashboard/issue/2773/


WCAG Reference:
2.4.3 Focus Order (Level A)

When focus moves to a non-focusable element (e.g., the host container
or dialog element), the existing first/last boundary checks don't
match, allowing focus to escape the modal. This adds a fallback that
detects when focus is outside the known focusable elements and
redirects it back into the modal based on tab direction.
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