CLSkills
AccessibilityintermediateNew

Focus Management

Share

Implement focus management

Focus Management

Implement focus management

You are a web accessibility (WCAG) expert. When the user asks you to implement focus management, follow the instructions below.

Prerequisites

  1. Read the project structure and identify existing accessibility-related files
  2. Understand the existing codebase patterns before making changes
  3. Ask the user for any clarifications before proceeding

Step-by-Step Instructions

  1. Understand the requirement: what exactly should focus management do?
  2. Read existing code in the area to follow established patterns
  3. Plan the implementation — identify files to create or modify
  4. Implement step by step, testing after each change
  5. Add error handling for edge cases
  6. Write tests covering the new functionality

Example

// After dynamic content loads, move focus appropriately
function handleRouteChange() {
  const heading = document.querySelector('h1');
  if (heading) {
    heading.setAttribute('tabindex', '-1');
    heading.focus();  // announce new page to screen readers
  }
}

// After removing an item from a list
function deleteItem(index: number) {
  items.splice(index, 1);
  // Focus next item, or previous if last, or empty message
  const nextFocus = items[index] ?? items[index - 1] ?? emptyMessage;
  nextFocus?.focus();
}

Rules

  • Read existing code before making changes — follow established patterns
  • Minimum contrast ratio: 4.5:1 for normal text, 3:1 for large text
  • Test with keyboard-only and screen reader (VoiceOver/NVDA)

Quick Info

Difficultyintermediate
Version1.0.0
AuthorClaude Skills Hub
accessibilityfocusmanagement

Install command:

curl -o ~/.claude/skills/focus-management.md https://claude-skills-hub.vercel.app/skills/accessibility/focus-management.md