// Automatically validate Moodle templates, JavaScript, and CSS for WCAG 2.1 Level AA accessibility compliance. Checks semantic HTML, ARIA patterns, keyboard navigation, color contrast, and screen reader compatibility. Activates when working with Mustache templates, AMD modules, or discussing accessibility, a11y, WCAG, screen readers, or keyboard navigation.
| name | wcag-validator |
| description | Automatically validate Moodle templates, JavaScript, and CSS for WCAG 2.1 Level AA accessibility compliance. Checks semantic HTML, ARIA patterns, keyboard navigation, color contrast, and screen reader compatibility. Activates when working with Mustache templates, AMD modules, or discussing accessibility, a11y, WCAG, screen readers, or keyboard navigation. |
| allowed-tools | Read, Grep, Bash |
This skill activates when:
โ Proper Document Structure
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Descriptive Page Title</title>
</head>
<body>
<!-- Content -->
</body>
</html>
โ Heading Hierarchy
โ Semantic Elements
<nav>, <main>, <aside>, <footer>, <article>, <section><div> for everythingโ Landmarks
<header role="banner">
<nav role="navigation" aria-label="Main">
<main role="main">
<aside role="complementary">
<footer role="contentinfo">
โ Alt Text
<!-- Informative image -->
<img src="chart.png" alt="Bar chart showing 60% increase in completion rates">
<!-- Decorative image -->
<img src="divider.png" alt="" role="presentation">
<!-- Linked image -->
<a href="/course/view.php?id=1">
<img src="icon.png" alt="Go to Introduction to Programming course">
</a>
โ Complex Images
<img src="diagram.png"
alt="Process flowchart"
aria-describedby="diagram-desc">
<div id="diagram-desc" class="sr-only">
Detailed description: The process starts with...
</div>
โ Label Association
<!-- Explicit association -->
<label for="username">Username</label>
<input type="text" id="username" name="username">
<!-- Implicit association -->
<label>
Email
<input type="email" name="email">
</label>
โ Required Fields
<label for="folder">
Folder name
<span class="text-danger" aria-label="required">*</span>
</label>
<input type="text"
id="folder"
required
aria-required="true">
โ Error Handling
<div class="form-group {{#error}}has-error{{/error}}">
<label for="email">Email</label>
<input type="email"
id="email"
aria-invalid="{{#error}}true{{/error}}"
aria-describedby="{{#error}}email-error{{/error}}">
{{#error}}
<div id="email-error" class="text-danger" role="alert">
{{error}}
</div>
{{/error}}
</div>
โ Field Instructions
<label for="password">Password</label>
<input type="password"
id="password"
aria-describedby="password-requirements">
<small id="password-requirements">
Must be at least 8 characters with one number
</small>
โ Buttons
<!-- Text button -->
<button type="button">Save Changes</button>
<!-- Icon button -->
<button type="button" aria-label="Delete file">
<i class="fa fa-trash" aria-hidden="true"></i>
</button>
<!-- Loading state -->
<button type="submit" aria-busy="true">
<span class="spinner" aria-hidden="true"></span>
Loading...
</button>
โ Links
<!-- Descriptive text -->
<a href="file.pdf">Download assignment guidelines (PDF, 2MB)</a>
<!-- Icon link -->
<a href="/edit" aria-label="Edit folder settings">
<i class="fa fa-edit" aria-hidden="true"></i>
</a>
<!-- External link -->
<a href="https://example.com"
target="_blank"
rel="noopener noreferrer">
External resource
<span class="sr-only">(opens in new window)</span>
</a>
โ Skip Links
<a href="#main-content" class="sr-only sr-only-focusable">
Skip to main content
</a>
โ Live Regions
<!-- Polite announcements (non-urgent) -->
<div aria-live="polite" aria-atomic="true" class="sr-only"></div>
<!-- Assertive announcements (urgent) -->
<div aria-live="assertive" aria-atomic="true" class="sr-only"></div>
<!-- Status updates -->
<div role="status" aria-live="polite">
File uploaded successfully
</div>
<!-- Alerts -->
<div role="alert">
Error: Connection failed
</div>
โ Dialogs/Modals
<div role="dialog"
aria-labelledby="dialog-title"
aria-describedby="dialog-desc"
aria-modal="true">
<h2 id="dialog-title">Confirm Deletion</h2>
<p id="dialog-desc">Are you sure you want to delete this file?</p>
<button type="button" class="btn-danger">Delete</button>
<button type="button" class="btn-secondary">Cancel</button>
</div>
โ Tabs
<div role="tablist" aria-label="Content views">
<button role="tab"
aria-selected="true"
aria-controls="tree-panel"
id="tree-tab">
Tree View
</button>
<button role="tab"
aria-selected="false"
aria-controls="table-panel"
id="table-tab"
tabindex="-1">
Table View
</button>
</div>
<div role="tabpanel"
id="tree-panel"
aria-labelledby="tree-tab">
<!-- Tree view content -->
</div>
<div role="tabpanel"
id="table-panel"
aria-labelledby="table-tab"
hidden>
<!-- Table view content -->
</div>
โ Focus Management
// โ
Trap focus in modal
const trapFocus = (element) => {
const focusableElements = element.querySelectorAll(
'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'
);
const firstElement = focusableElements[0];
const lastElement = focusableElements[focusableElements.length - 1];
element.addEventListener('keydown', (e) => {
if (e.key === 'Tab') {
if (e.shiftKey && document.activeElement === firstElement) {
e.preventDefault();
lastElement.focus();
} else if (!e.shiftKey && document.activeElement === lastElement) {
e.preventDefault();
firstElement.focus();
}
}
});
};
// โ
Return focus after modal closes
let previousFocus = null;
const openModal = (modal) => {
previousFocus = document.activeElement;
modal.showModal();
modal.querySelector('button').focus();
};
const closeModal = (modal) => {
modal.close();
if (previousFocus) {
previousFocus.focus();
}
};
โ Keyboard Event Handlers
// โ
Handle both click and keyboard
element.addEventListener('click', handleAction);
element.addEventListener('keydown', (e) => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
handleAction();
}
});
// โ
Escape to close
dialog.addEventListener('keydown', (e) => {
if (e.key === 'Escape') {
closeDialog();
}
});
โ Contrast Ratios (WCAG AA)
/* โ Poor contrast (2.8:1) */
.text {
color: #999;
background: #fff;
}
/* โ
Good contrast (4.7:1) */
.text {
color: #666;
background: #fff;
}
/* โ
Excellent contrast (7.0:1) */
.text {
color: #333;
background: #fff;
}
โ Don't Rely on Color Alone
<!-- โ Color only -->
<span style="color: red;">Error</span>
<!-- โ
Color + icon + text -->
<span class="text-danger">
<i class="fa fa-exclamation-circle" aria-hidden="true"></i>
Error: Invalid input
</span>
โ Screen Reader Announcements
// โ
Announce loading state
const announceLoading = () => {
const liveRegion = document.querySelector('[aria-live="polite"]');
liveRegion.textContent = 'Loading files...';
};
// โ
Announce completion
const announceComplete = (count) => {
const liveRegion = document.querySelector('[aria-live="polite"]');
liveRegion.textContent = `${count} files loaded successfully`;
setTimeout(() => {
liveRegion.textContent = '';
}, 1000);
};
// โ
Announce errors
const announceError = (message) => {
const liveRegion = document.querySelector('[aria-live="assertive"]');
liveRegion.textContent = `Error: ${message}`;
};
# Use grep to find potential issues
grep -r "onclick=" templates/ # Check for click handlers on non-buttons
grep -r "<img" templates/ | grep -v "alt=" # Find images without alt
grep -r "<input" templates/ | grep -v "label" # Find unlabeled inputs
For each .mustache file:
For each AMD module:
โฟ Accessibility Validation Report
File: templates/folder_view.mustache
Status: โ FAILED (3 issues)
Issues:
โ Line 45: Image missing alt attribute
<img src="{{icon}}">
Fix: <img src="{{icon}}" alt="{{iconDescription}}">
โ Line 78: Button not keyboard accessible
<div onclick="deleteFile()">Delete</div>
Fix: <button type="button" onclick="deleteFile()">Delete</button>
โ Line 102: Form input missing label
<input type="text" name="foldername">
Fix: <label for="folder-{{id}}">Folder name</label>
<input type="text" id="folder-{{id}}" name="foldername">
Recommendations:
- Add aria-live region for file loading status
- Implement keyboard navigation for file list
- Add skip link to file content
WCAG 2.1 AA Compliance: 68% โ Target: 100%
<div class="card" role="region" aria-labelledby="card-title-{{id}}">
<div class="card-header">
<h3 id="card-title-{{id}}">{{title}}</h3>
</div>
<div class="card-body">
<p>{{description}}</p>
</div>
<div class="card-footer">
<a href="{{url}}"
class="btn btn-primary"
aria-label="View details for {{title}}">
View Details
</a>
</div>
</div>
<table class="table">
<caption>List of course files</caption>
<thead>
<tr>
<th scope="col">Filename</th>
<th scope="col">Size</th>
<th scope="col">Modified</th>
<th scope="col">Actions</th>
</tr>
</thead>
<tbody>
{{#files}}
<tr>
<th scope="row">{{name}}</th>
<td>{{size}}</td>
<td>{{modified}}</td>
<td>
<button type="button"
class="btn btn-sm"
aria-label="Download {{name}}">
Download
</button>
</td>
</tr>
{{/files}}
</tbody>
</table>
/m:a11y command