Skip to content

Conversation

@arthurgousset
Copy link
Collaborator

Summary

Fixes WCAG 2.1.2 (No Keyboard Trap) by ensuring that when users press Escape to close a dropdown menu, focus returns to the menu trigger button.

Issue: When keyboard users opened a dropdown menu (e.g., "Per chi insegna", "Giuridico") and pressed Escape to close it, focus was lost, leaving users disoriented and requiring them to tab through the entire page again to return to the menu.

Solution:

  • Changed keydown listener from component-level to document-level to ensure Escape works from any focus location within the menu
  • Added focus restoration logic that returns focus to the trigger button after closing
  • Used setTimeout(0) to defer focus until after Stencil's render cycle completes
  • Added event.preventDefault() to prevent default Escape behavior

Test Plan

  • Open a dropdown menu using keyboard (Space or Enter)
  • Press Escape to close the menu
  • Verify focus returns to the menu trigger button
  • Verify menu closes properly
  • Test with multiple menus (Giuridico, Saggistica, Per chi insegna, etc.)
  • Code review completed and approved

Evidence

Resolves issue #127: "Escape key fails to close 'Per chi insegna' dropdown menu"

View full audit details: https://app.workback.ai/dashboard/issue/127/


WCAG Reference: 2.1.2 No Keyboard Trap

When users press Escape to close a dropdown menu, focus now properly
returns to the menu trigger button that opened it. This prevents
keyboard users from losing their place in the navigation and ensures
compliance with WCAG 2.1.2 (No Keyboard Trap).

The fix also changes the keydown listener from component-level to
document-level to ensure Escape works regardless of where focus is
within the dropdown menu.
@arthurgousset
Copy link
Collaborator Author

Note: This PR also resolves issue #122 (WCAG 1.4.13 - Content on Hover or Focus). The same fix addresses both:

  • Issue #127 (WCAG 2.1.2): Focus management - returns focus to trigger after ESC
  • Issue #122 (WCAG 1.4.13): ESC key dismissal of hover/focus content

Evidence for issue #122: https://app.workback.ai/dashboard/issue/122/

@DarioSacco
Copy link
Collaborator

Looks good to me.

@arthurgousset arthurgousset merged commit dd0c4f1 into main Nov 24, 2025
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.

3 participants