惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

爱范儿
爱范儿
腾讯CDC
博客园 - 司徒正美
A
About on SuperTechFans
H
Help Net Security
J
Java Code Geeks
C
Check Point Blog
B
Blog RSS Feed
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
MongoDB | Blog
MongoDB | Blog
U
Unit 42
Hugging Face - Blog
Hugging Face - Blog
Last Week in AI
Last Week in AI
MyScale Blog
MyScale Blog
V
Visual Studio Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
I
InfoQ
H
Hackread – Cybersecurity News, Data Breaches, AI and More
F
Fortinet All Blogs
博客园 - 聂微东
酷 壳 – CoolShell
酷 壳 – CoolShell
GbyAI
GbyAI
博客园 - 【当耐特】
雷峰网
雷峰网

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Keyboard Navigation Testing: A Developer Complete Guide t...
DevToolsmith · 2026-06-12 · via DEV Community

DevToolsmith

Keyboard accessibility is one of the most important — and most neglected — aspects of web accessibility. An estimated 2.5 million Americans have motor disabilities that prevent mouse use. If your site can't be operated entirely by keyboard, you're excluding them completely.

The Four Core Principles

WCAG 2.2 Principle 2 (Operable) contains the keyboard requirements:

  • 2.1.1 Keyboard (AA): All functionality must be operable via keyboard
  • 2.1.2 No Keyboard Trap (AA): If focus moves into a component, it must be possible to move it out
  • 2.4.3 Focus Order (AA): If page can be navigated sequentially, order must be logical and predictable
  • 2.4.7 Focus Visible (AA): Any keyboard-operable UI must have a visible focus indicator
  • 2.4.11 Focus Appearance (AA, new in 2.2): Focus indicator must meet size and contrast requirements

Testing Without Automated Tools

Start with the basic keyboard test:

  1. Unplug (or ignore) your mouse
  2. Press Tab to move forward through interactive elements
  3. Press Shift+Tab to move backward
  4. Use Enter/Space to activate buttons, links, checkboxes
  5. Use arrow keys for radio groups, menus, sliders
  6. Use Escape to close dialogs and menus

Any element you can't reach or activate? That's a WCAG 2.1.1 failure.

The Most Common Keyboard Failures

Custom dropdowns and menus

// ❌ Keyboard inaccessible
function Dropdown({ items }) {
  return (
    <div onClick={toggle} className="dropdown">
      {items.map(item => (
        <div onClick={() => select(item)}>{item.label}</div>
      ))}
    </div>
  );
}

// ✅ Fully keyboard accessible
function Dropdown({ items }) {
  return (
    <div
      role="combobox"
      aria-haspopup="listbox"
      aria-expanded={isOpen}
      tabIndex={0}
      onKeyDown={handleKeyDown} // handles Enter, Space, Arrows, Escape
      className="dropdown"
    >
      <ul role="listbox">
        {items.map((item, i) => (
          <li
            key={item.id}
            role="option"
            tabIndex={-1}
            aria-selected={i === activeIndex}
            onKeyDown={e => e.key === 'Enter' && select(item)}
          >
            {item.label}
          </li>
        ))}
      </ul>
    </div>
  );
}

Modals and dialogs

Modal dialogs must:

  1. Move focus into the dialog when it opens
  2. Trap focus inside while it's open (Tab cycles within)
  3. Return focus to the trigger element when it closes
function openModal(modalEl, triggerEl) {
  const focusable = modalEl.querySelectorAll(
    'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'
  );
  const first = focusable[0];
  const last  = focusable[focusable.length - 1];

  first.focus();

  modalEl.addEventListener('keydown', (e) => {
    if (e.key === 'Tab') {
      if (e.shiftKey && document.activeElement === first) {
        e.preventDefault();
        last.focus();
      } else if (!e.shiftKey && document.activeElement === last) {
        e.preventDefault();
        first.focus();
      }
    }
    if (e.key === 'Escape') closeModal(triggerEl);
  });
}

Removing default focus styles

The single most common mistake: outline: none in a CSS reset.

/* ❌ Never do this globally */
* { outline: none; }

/* ✅ Remove default, replace with better style */
:focus { outline: none; }
:focus-visible {
  outline: 3px solid #0066CC;
  outline-offset: 2px;
  border-radius: 2px;
}

The :focus-visible pseudo-class shows focus only when navigating by keyboard, not on mouse click — giving you the best of both worlds.

Skip Links

Users navigating by keyboard should be able to skip repetitive navigation. A skip link is the first focusable element in your page:

<a href="#main-content" class="skip-link">Skip to main content</a>

.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: #000;
  color: #fff;
  padding: 8px 16px;
  z-index: 9999;
}
.skip-link:focus { top: 0; }

Automated Testing Coverage

Automated scanners can catch about 40% of keyboard accessibility issues — primarily missing tabindex, incorrect roles, and missing focus styles. Tools like AccessiScan provide a starting point with 201 automated checks, but the Tab-through test above is still essential for catching interaction patterns that automation misses.