Skip to content

Generate Keyboard Navigation Test Cases with AI

Updated 2026-06-08·basic·Accessibility Testing

Returns numbered keyboard navigation test cases covering Tab order, focus visibility, focus trap in modals/menus, Escape key behavior, skip links, focus return after modal close, and roving tabindex for composite widgets — with expected behavior per case.

When to use it

  • Manual accessibility testing for a new component or page.
  • Auditing keyboard accessibility before a release.
  • Onboarding QA engineers to keyboard testing fundamentals.
  • Validating focus management after a routing or modal refactor.

The prompt

XML-tagged — best for Claude 4.x

<role>
You are an accessibility-focused QA engineer. You know keyboard accessibility is the foundation of accessibility — screen reader testing assumes keyboard works. You test focus, not clicks.
</role>

<context>
Keyboard patterns to verify:
- **Tab order** — sequential focus follows visual / reading order
- **Focus visibility** — every focused element has a visible indicator
- **Focus trap** — modals and menus trap focus while open
- **Focus return** — closing a modal returns focus to the trigger
- **Skip links** — first focusable item lets users skip nav
- **Escape behavior** — Esc dismisses modals, popovers, menus
- **Roving tabindex** — composite widgets (tabs, menubars) use single tab stop
- **Arrow keys** — within composite widgets, arrows move within
- **Enter / Space** — activates buttons, links, custom controls
</context>

<task>
For the page or component below, generate numbered keyboard test cases covering:
1. Tab forward through the entire page / component
2. Tab order matches visual layout
3. Focus visibility on each interactive element
4. Modal / dialog focus trap (if applicable)
5. Modal close returns focus to trigger
6. Skip link (if applicable to page-level test)
7. Escape closes overlays
8. Roving tabindex for composite widgets (tabs, menus, lists)
9. Enter / Space activation
10. Shift+Tab reverse navigation
</task>

<input>
Page or component description: {target}
Composite widgets present: {widgets}
Modals / overlays present: {overlays}
</input>

<constraints>
- Number each case sequentially (1, 2, 3...).
- Each case states the key sequence AND the expected focus location after.
- Focus visibility is tested separately per element — don't lump it as "all elements are visible".
- Composite widgets MUST have roving tabindex tests (Tab gets you in; arrows navigate within).
- Include focus return test for every modal-like component.
- Skip link test required for page-level audits.
</constraints>

<output_format>
Markdown document with a numbered list. Each case: ID, key sequence, expected focus location, expected behavior. Followed by a 2-3 bullet "Common failures" list specific to this component.
</output_format>

Before writing, identify whether this is a page-level test (need skip link) or component-level test (no skip link).

Example

Common pitfalls

  • Focus visibility tested generically ('all elements visible') instead of per element — fails to catch the one element with `outline: none`.
  • Roving tabindex tests omitted for tab lists / menus — they become 4 tab stops instead of 1.
  • Focus return tests skipped — modal closes, focus drops to body, user is lost.
  • Floating elements (position: fixed) skipped from tab order assertions even though they're commonly broken.

Tips

  • Test by unplugging your mouse for 30 minutes. If you can't use the page, your users with disabilities can't either.
  • Pair with `screen-reader-scenarios` — keyboard tests verify focus mechanics; screen reader verifies announcements.
  • Add Playwright keyboard tests for the most error-prone patterns (focus trap, focus return).
  • Verify focus indicators in BOTH light and dark mode — focus styles often break across themes.

FAQ

For composite widgets where multiple items share a single tab stop — tab lists, menubars, listboxes, treegrids. ARIA Authoring Practices Guide (APG) defines these. For simple lists of links, use natural tab order, not roving.

Related prompts