-
-
Notifications
You must be signed in to change notification settings - Fork 1
feat: add additional audits for accessibility and usability checks #178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ad30fe9
feat: add additional audits for accessibility and usability checks
dermatz 002d30f
feat: enhance audits for duplicate IDs and interactive elements
dermatz d492c1e
feat: update minimum size for small touch targets audit
dermatz 81ae5e4
feat: update touch target size description for accessibility audit
dermatz bfdcc29
feat: exclude toolbar elements from highlight application
dermatz 2df5ff2
feat: clarify description for unsafe target="_blank" audit
dermatz 877edcd
feat: add additional check for elements within the toolbar
dermatz cfab08a
feat: add warning styles and enhance audit checks for toolbar elements
dermatz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/view/frontend/web/js/toolbar/audits/buttons-without-type.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| /** | ||
| * MageForge Toolbar Audit – Buttons without type | ||
| * | ||
| * A <button> without an explicit type attribute defaults to type="submit", | ||
| * which can accidentally submit parent forms. Always set type="button", | ||
| * type="submit", or type="reset" explicitly. | ||
| */ | ||
|
|
||
| import { applyHighlight, clearHighlight } from './highlight.js'; | ||
|
|
||
| /** @type {import('./index.js').AuditDefinition} */ | ||
| export default { | ||
| key: 'buttons-without-type', | ||
| icon: '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M8 13v-8.5a1.5 1.5 0 0 1 3 0v7.5"></path><path d="M11 11.5a1.5 1.5 0 0 1 3 0v1.5"></path><path d="M14 12a1.5 1.5 0 0 1 3 0v2"></path><path d="M17 13.5a1.5 1.5 0 0 1 3 0v3.5a6 6 0 0 1 -6 6h-2h.208a6 6 0 0 1 -5.012 -2.7l-.196 -.3c-.312 -.479 -1.407 -2.388 -3.286 -5.728a1.5 1.5 0 0 1 .536 -2.022a1.867 1.867 0 0 1 2.28 .28l1.47 1.47"></path></svg>', | ||
| label: 'Buttons without a type', | ||
| description: 'Highlight a button missing an explicit type attribute (defaults to submit)', | ||
|
|
||
| /** | ||
| * @param {object} context - Alpine toolbar component instance | ||
| * @param {boolean} active - true = activate, false = deactivate | ||
| */ | ||
| run(context, active) { | ||
| if (!active) { | ||
| clearHighlight(this.key); | ||
| return; | ||
| } | ||
|
|
||
| const buttons = Array.from(document.querySelectorAll('button')).filter(btn => { | ||
| const type = btn.getAttribute('type'); | ||
| if (type !== null && type.trim() !== '') return false; | ||
| if (!btn.offsetParent && getComputedStyle(btn).position !== 'fixed') return false; | ||
| const style = getComputedStyle(btn); | ||
| if (style.visibility === 'hidden' || style.display === 'none' || style.opacity === '0') return false; | ||
| return true; | ||
| }); | ||
|
|
||
| applyHighlight(buttons, this.key, context); | ||
| }, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| /** | ||
| * MageForge Toolbar Audit – Duplicate IDs | ||
| * | ||
| * IDs must be unique per document. Duplicate IDs break label associations, | ||
| * aria-labelledby / aria-describedby references, fragment links, and cause | ||
| * unpredictable behaviour with JavaScript querySelector. | ||
| * | ||
| * Icon source: Tabler Icons (MIT) | ||
| */ | ||
|
|
||
| import { applyHighlight, clearHighlight } from './highlight.js'; | ||
|
|
||
| /** @type {import('./index.js').AuditDefinition} */ | ||
| export default { | ||
| key: 'duplicate-ids', | ||
| icon: '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M7 8a4 4 0 0 1 4 4a4 4 0 0 1 4 -4"></path><path d="M7 16a4 4 0 0 0 4 -4a4 4 0 0 0 4 4"></path><path d="M9 12h6"></path><path d="M3 12h2"></path><path d="M19 12h2"></path></svg>', | ||
| label: 'Duplicate IDs', | ||
| description: 'Highlight elements sharing an ID with at least one other element', | ||
|
|
||
| /** | ||
| * @param {object} context - Alpine toolbar component instance | ||
| * @param {boolean} active - true = activate, false = deactivate | ||
| */ | ||
| run(context, active) { | ||
| if (!active) { | ||
| clearHighlight(this.key); | ||
| context.setAuditDescription(this.key, this.description); | ||
| return; | ||
| } | ||
|
|
||
| /** @type {Map<string, Element[]>} */ | ||
| const idMap = new Map(); | ||
|
|
||
| document.querySelectorAll('[id]').forEach(el => { | ||
| const id = el.id; | ||
| if (!id) return; | ||
| if (el.closest('.mageforge-toolbar')) return; | ||
| if (!idMap.has(id)) { | ||
| idMap.set(id, []); | ||
| } | ||
| idMap.get(id).push(el); | ||
| }); | ||
|
|
||
| /** @type {string[]} */ | ||
| const duplicateIdNames = []; | ||
| const duplicates = []; | ||
| idMap.forEach((els, id) => { | ||
| if (els.length > 1) { | ||
| duplicateIdNames.push(`#${id} (×${els.length})`); | ||
| els.forEach(el => duplicates.push(el)); | ||
| } | ||
| }); | ||
|
|
||
| if (duplicates.length > 0) { | ||
| context.setAuditDescription( | ||
| this.key, | ||
| `Duplicate: ${duplicateIdNames.join(', ')}` | ||
| ); | ||
| } else { | ||
| context.setAuditDescription(this.key, this.description); | ||
| } | ||
|
|
||
| applyHighlight(duplicates, this.key, context); | ||
| }, | ||
| }; | ||
52 changes: 52 additions & 0 deletions
52
src/view/frontend/web/js/toolbar/audits/empty-interactive.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| /** | ||
| * MageForge Toolbar Audit – Empty Links & Buttons | ||
| * | ||
| * Links and buttons without an accessible name are unusable for screen | ||
| * reader and keyboard users (WCAG 2.1 SC 4.1.2, 2.4.6). | ||
| */ | ||
|
|
||
| import { applyHighlight, clearHighlight } from './highlight.js'; | ||
|
|
||
| /** @type {import('./index.js').AuditDefinition} */ | ||
| export default { | ||
| key: 'empty-interactive', | ||
| icon: '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M17 12h-14"></path><path d="M6 9l-3 3l3 3"></path><path d="M20 6v.01"></path><path d="M20 12v.01"></path><path d="M20 18v.01"></path></svg>', | ||
| label: 'Empty Links & Buttons', | ||
| description: 'Highlight links and buttons missing an accessible name', | ||
|
|
||
| /** | ||
| * @param {object} context - Alpine toolbar component instance | ||
| * @param {boolean} active - true = activate, false = deactivate | ||
| */ | ||
| run(context, active) { | ||
| if (!active) { | ||
| clearHighlight(this.key); | ||
| return; | ||
| } | ||
|
|
||
| const elements = Array.from(document.querySelectorAll('a[href], button')).filter(el => { | ||
| // Visibility check | ||
| if (!el.offsetParent && getComputedStyle(el).position !== 'fixed') return false; | ||
| const style = getComputedStyle(el); | ||
| if (style.visibility === 'hidden' || style.display === 'none' || style.opacity === '0') return false; | ||
|
|
||
| // Accessible name sources | ||
| if (el.getAttribute('aria-label')?.trim()) return false; | ||
| if (el.getAttribute('title')?.trim()) return false; | ||
| if (el.getAttribute('aria-labelledby')?.trim().split(/\s+/).some(id => document.getElementById(id)?.textContent.trim())) return false; | ||
|
|
||
| // Text content (excluding whitespace-only) | ||
| if (el.textContent.trim()) return false; | ||
|
|
||
| // Child <img> with non-empty alt (trimmed) | ||
| if (Array.from(el.querySelectorAll('img[alt]')).some(img => img.getAttribute('alt')?.trim())) return false; | ||
|
|
||
| // Child <svg> with a <title> element | ||
| if (el.querySelector('svg title')?.textContent.trim()) return false; | ||
|
|
||
| return true; | ||
| }); | ||
|
|
||
| applyHighlight(elements, this.key, context); | ||
| }, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.