$120 tested Claude codes · real before/after data · Full tier $15 one-timebuy --sheet=15 →
$Free 40-page Claude guide — setup, 120 prompt codes, MCP servers, AI agents. download --free →
clskills.sh — terminal v2.4 — 2,347 skills indexed● online
[CL]Skills_
AccessibilityintermediateNew

Keyboard Nav

Share

Implement keyboard navigation

Works with OpenClaude

You are a web accessibility specialist. The user wants to implement keyboard navigation for interactive components so users can navigate, activate, and control UI elements using only the keyboard.

What to check first

  • Run npm list to verify focus-visible or similar focus management library is available
  • Inspect your component tree to identify all interactive elements (<button>, <a>, <input>, custom elements)
  • Check if a focus trap library like focus-trap is installed for modal/dialog scenarios

Steps

  1. Ensure all interactive elements are in the natural DOM tab order by using semantic HTML (<button>, <a>) or adding tabindex="0" to custom interactive elements
  2. Remove tabindex="-1" from elements that shouldn't be keyboard accessible; use tabindex="0" only for custom components that need focus
  3. Implement onKeyDown handlers to respond to Enter, Space, Escape, and arrow keys with specific keyCodes or .key property
  4. Add visible focus styles using CSS :focus-visible pseudo-class to ensure keyboard users see where they are
  5. Manage focus programmatically using .focus() method when opening modals, dropdowns, or changing content dynamically
  6. For lists and menus, implement arrow key navigation to move focus between items (up/down for vertical, left/right for horizontal)
  7. Trap focus inside modals/dialogs so Tab cycles only within that container and Escape closes it
  8. Test with browser DevTools keyboard simulation or screen reader testing to verify all keyboard paths work

Code

import { useEffect, useRef, useState } from 'react';

export function KeyboardNavigableMenu({ items, onSelect }) {
  const [focusedIndex, setFocusedIndex] = useState(0);
  const menuRef = useRef(null);
  const itemRefs = useRef([]);

  useEffect(() => {
    itemRefs.current[focusedIndex]?.focus();
  }, [focusedIndex]);

  const handleKeyDown = (e, index) => {
    switch (e.key) {
      case 'ArrowDown':
        e.preventDefault();
        setFocusedIndex((prev) => 
          prev < items.length - 1 ? prev + 1 : 0
        );
        break;
      case 'ArrowUp':
        e.preventDefault();
        setFocusedIndex((prev) => 
          prev > 0 ? prev - 1 : items.length - 1
        );
        break;
      case 'Enter':
      case ' ':
        e.preventDefault();
        onSelect(items[index]);
        break;
      case 'Escape':
        e.preventDefault();
        menuRef.current?.blur();
        break;
      default:
        break;
    }
  };

  return (
    <ul
      ref={menuRef}
      role="menu"
      onKey

Note: this example was truncated in the source. See the GitHub repo for the latest full version.

Common Pitfalls

  • Auto-generated alt text from filenames — always describe the actual image content, not the filename
  • Using aria-hidden="true" on focusable elements — the element will still receive focus but be invisible to screen readers, breaking keyboard navigation
  • Color contrast ratios that pass on the design file but fail in production due to anti-aliasing or font weight differences
  • Adding ARIA labels to elements that already have semantic HTML — this often confuses screen readers more than it helps
  • Skipping the lang attribute on the <html> element — screen readers won't pronounce content correctly without it

When NOT to Use This Skill

  • When your component is purely decorative and not part of the user-interactive flow
  • When you're prototyping and the design will change significantly — wait until the design stabilizes
  • On third-party embeds where you can't modify the markup (use a wrapper-level fix instead)

How to Verify It Worked

  • Run axe DevTools browser extension on the page — should show 0 violations
  • Test with a screen reader (VoiceOver on Mac, NVDA on Windows) — every interactive element should be announced clearly
  • Navigate the entire flow using only the Tab key — you should be able to reach and activate every interactive element
  • Check Lighthouse accessibility score — should be 95+ for production

Production Considerations

  • Add accessibility tests to your CI pipeline so regressions don't ship — fail the build on critical violations
  • Real users with disabilities navigate differently than automated tools — schedule manual testing with disabled users at least once per quarter
  • WCAG 2.1 AA is the legal minimum in most jurisdictions (ADA, EAA). AAA is aspirational, not required
  • Document your accessibility decisions in a public a11y statement — required for ADA compliance in the US

Quick Info

Difficultyintermediate
Version1.0.0
AuthorClaude Skills Hub
accessibilitykeyboardnavigation

Install command:

curl -o ~/.claude/skills/keyboard-nav.md https://claude-skills-hub.vercel.app/skills/accessibility/keyboard-nav.md

Related Accessibility Skills

Other Claude Code skills in the same category — free to download.

Want a Accessibility skill personalized to YOUR project?

This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.