Storybook addon that provides comprehensive accessibility testing for UI components using axe-core engine to ensure WCAG compliance
—
Comprehensive mapping system that converts axe-core rule violations into user-friendly descriptions and remediation guidance.
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"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."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:
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="".'
}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."
}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.'
}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.'
}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.'
}The rule mapping system is integrated throughout the addon's UI components:
// Used in A11YPanel to show friendly titles
const violationTitle = getTitleForAxeResult(violation);
const violationSummary = getFriendlySummaryForAxeResult(violation);// 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 });
});// Used for contextual help and tooltips
const helpText = getFriendlySummaryForAxeResult(result);
showTooltip(helpText);When no mapping exists for a rule:
The complete rule mapping covers:
While the rule mapping is comprehensive, organizations can extend it by:
combinedRulesMapThe 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