CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-storybook--addon-a11y

Storybook addon that provides comprehensive accessibility testing for UI components using axe-core engine to ensure WCAG compliance

Pending
Overview
Eval results
Files

rule-mapping.mddocs/

Rule Mapping and Descriptions

Comprehensive mapping system that converts axe-core rule violations into user-friendly descriptions and remediation guidance.

Capabilities

Rule Title Mapping

Exported utility that converts axe-core rule IDs into user-friendly titles.

/**
 * Gets user-friendly title for an axe accessibility test result
 * @param axeResult - Enhanced result from accessibility testing
 * @returns Human-readable title for the rule or rule ID if no mapping exists
 */
function getTitleForAxeResult(axeResult: EnhancedResult): string;

This function provides user-friendly rule titles for accessibility violations and can be imported and used directly:

import { getTitleForAxeResult } from '@storybook/addon-a11y';

// Get a friendly title for a violation
const title = getTitleForAxeResult(violationResult);
console.log(title); // "Color contrast" instead of "color-contrast"

Rule Summary Mapping

Exported utility that provides user-friendly summaries and remediation guidance.

/**
 * Gets user-friendly summary for an axe accessibility test result
 * @param axeResult - Enhanced result from accessibility testing
 * @returns Friendly remediation summary or description fallback
 */
function getFriendlySummaryForAxeResult(
  axeResult: EnhancedResult
): string | undefined;

This function provides user-friendly remediation guidance and can be imported and used directly:

import { getFriendlySummaryForAxeResult } from '@storybook/addon-a11y';

// Get friendly remediation guidance for a violation
const guidance = getFriendlySummaryForAxeResult(violationResult);
console.log(guidance); // "The color contrast between text and its background meets WCAG AA contrast ratio."

Rule Map Structure

Complete mapping of axe-core rules to user-friendly descriptions.

type AxeRuleMap = {
  [axeId: string]: {
    /** The simple name of the rule */
    title: string;
    /** The summary of the rule from axe-core */
    axeSummary: string;
    /** The UX-friendly summary of the rule */
    friendlySummary: string;
  };
};

const combinedRulesMap: AxeRuleMap;

The rule map includes comprehensive coverage for:

  • WCAG 2.0 A/AA Success Criteria
  • WCAG 2.1 A/AA Success Criteria
  • WCAG 2.2 A/AA Success Criteria
  • WCAG AAA Success Criteria
  • Best Practice Rules
  • Experimental Rules
  • Deprecated Rules

Rule Categories

WCAG 2.0 A/AA Rules

Essential accessibility rules aligned with WCAG 2.0 Level A and AA success criteria.

Example Rules:

// Color contrast requirements
'color-contrast': {
  title: 'Color contrast',
  axeSummary: 'Ensure the contrast between foreground and background text meets WCAG 2 AA minimum thresholds',
  friendlySummary: 'The color contrast between text and its background meets WCAG AA contrast ratio.'
}

// Button accessibility
'button-name': {
  title: 'Button name',
  axeSummary: 'Ensure buttons have discernible text',
  friendlySummary: 'Every <button> needs a visible label or accessible name.'
}

// Image alt text
'image-alt': {
  title: 'Image alt text', 
  axeSummary: 'Ensure <img> elements have alternative text or a role of none/presentation',
  friendlySummary: 'Give every image alt text or mark it as decorative with alt="".'
}

WCAG 2.1 A/AA Rules

Additional rules introduced in WCAG 2.1 for enhanced accessibility.

Example Rules:

// Autocomplete attributes
'autocomplete-valid': {
  title: 'autocomplete attribute valid',
  axeSummary: 'Ensure the autocomplete attribute is correct and suitable for the form field',
  friendlySummary: "Use valid autocomplete values that match the form field's purpose."
}

// Text spacing
'avoid-inline-spacing': {
  title: 'Forced inline spacing',
  axeSummary: 'Ensure that text spacing set via inline styles can be adjusted with custom CSS',
  friendlySummary: "Don't lock in text spacing with forced (!important) inline styles—allow user CSS to adjust text spacing."
}

WCAG 2.2 A/AA Rules

Latest accessibility requirements from WCAG 2.2.

Example Rules:

// Touch target sizing
'target-size': {
  title: 'Touch target size',
  axeSummary: 'Ensure touch targets have sufficient size and space',
  friendlySummary: 'Make sure interactive elements are big enough and not too close together for touch.'
}

Best Practice Rules

Industry best practices beyond WCAG requirements.

Example Rules:

// Heading order
'heading-order': {
  title: 'Heading order',
  axeSummary: 'Ensure the order of headings is semantically correct (no skipping levels)',
  friendlySummary: "Use proper heading order (don't skip heading levels)."
}

// Landmark structure
'region': {
  title: 'Landmark regions',
  axeSummary: 'Ensure all page content is contained by landmarks',
  friendlySummary: 'Wrap all page content in appropriate landmark regions (<header>, <main>, <footer>, etc.).'
}

// Skip links
'skip-link': {
  title: 'Skip link',
  axeSummary: 'Ensure all "skip" links have a focusable target',
  friendlySummary: 'Make sure any "skip to content" link targets an existing, focusable element.'
}

ARIA Rules

Comprehensive ARIA (Accessible Rich Internet Applications) rules.

Example Rules:

// ARIA roles
'aria-roles': {
  title: 'ARIA role value',
  axeSummary: 'Ensure all elements with a role attribute use a valid value',
  friendlySummary: 'Use only valid values in the role attribute (no typos or invalid roles).'
}

// ARIA attributes
'aria-valid-attr': {
  title: 'ARIA attribute valid',
  axeSummary: 'Ensure attributes that begin with aria- are valid ARIA attributes',
  friendlySummary: 'Use only valid aria-* attributes (make sure the attribute name is correct).'
}

// ARIA required attributes
'aria-required-attr': {
  title: 'ARIA required attributes',
  axeSummary: 'Ensure elements with ARIA roles have all required ARIA attributes',
  friendlySummary: 'Include all required ARIA attributes for elements with that ARIA role.'
}

Usage in Components

The rule mapping system is integrated throughout the addon's UI components:

Panel Display

// Used in A11YPanel to show friendly titles
const violationTitle = getTitleForAxeResult(violation);
const violationSummary = getFriendlySummaryForAxeResult(violation);

Report Generation

// Used in Report component for detailed violation information
violations.forEach(violation => {
  const title = getTitleForAxeResult(violation);
  const guidance = getFriendlySummaryForAxeResult(violation);
  
  // Display title and guidance in the UI
  renderViolation({ title, guidance, ...violation });
});

Tooltip Information

// Used for contextual help and tooltips
const helpText = getFriendlySummaryForAxeResult(result);
showTooltip(helpText);

Fallback Behavior

When no mapping exists for a rule:

  • Title: Falls back to the original axe rule ID
  • Summary: Falls back to the axe-core description field
  • Graceful Degradation: Always provides some description even for unknown rules

Rule Categories Overview

The complete rule mapping covers:

  • 200+ WCAG Rules: Comprehensive coverage of WCAG 2.0, 2.1, and 2.2
  • 50+ Best Practice Rules: Industry standards beyond WCAG requirements
  • 30+ ARIA Rules: Complete ARIA implementation guidance
  • Experimental Rules: Cutting-edge accessibility requirements
  • Legacy Support: Deprecated rules for backward compatibility

Customization

While the rule mapping is comprehensive, organizations can extend it by:

  1. Contributing additional rules to the combinedRulesMap
  2. Overriding specific rule descriptions for organizational standards
  3. Adding custom rule categories for specialized accessibility requirements

The mapping system ensures that all accessibility violations are presented in user-friendly language with actionable remediation guidance.

Install with Tessl CLI

npx tessl i tessl/npm-storybook--addon-a11y

docs

configuration.md

index.md

rule-mapping.md

testing.md

ui-components.md

tile.json