Skip to content

Commit 2a91949

Browse files
committed
update issue counting and threshold checks in accessibility components
1 parent cc70f2b commit 2a91949

File tree

5 files changed

+27
-23
lines changed

5 files changed

+27
-23
lines changed

packages/devtools-a11y/src/core/components/IssueList.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,10 @@ export function A11yIssueList(props: A11yIssueListProps) {
7979
<div class={styles().summaryGrid}>
8080
<For each={IMPACTS}>
8181
{(impact) => {
82-
const count = () =>
83-
ally.allyResult.audit?.issues.reduce(
84-
(count, issue) =>
85-
issue.impact === impact && issue.meetsThreshold
86-
? count + 1
87-
: count,
88-
0,
89-
) || 0
82+
// Count issues from the reactive filteredIssues memo so counts update when config.threshold changes
83+
const issuesForImpact = () =>
84+
ally.filteredIssues().filter((issue) => issue.impact === impact)
85+
const count = () => issuesForImpact().length || 0
9086

9187
const active = () => ally.impactKey() === impact
9288

packages/devtools-a11y/src/core/components/Settings.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ export function A11ySettingsOverlay(props: A11ySettingsOverlayProps) {
6666
{ value: 'moderate', label: 'Moderate' },
6767
{ value: 'minor', label: 'Minor' },
6868
]}
69-
onChange={(value: string) =>
69+
onChange={(value: string) =>{
7070
setConfig('threshold', value as SeverityThreshold)
71-
}
71+
}}
7272
/>
7373
<Select<RuleSetPreset>
7474
label="Rule Set"
@@ -83,9 +83,9 @@ export function A11ySettingsOverlay(props: A11ySettingsOverlayProps) {
8383
{ value: 'best-practice', label: 'Best Practice' },
8484
{ value: 'all', label: 'All Rules' },
8585
]}
86-
onChange={(value: string) =>
86+
onChange={(value: string) => {
8787
setConfig('ruleSet', value as RuleSetPreset)
88-
}
88+
}}
8989
/>
9090
</div>
9191
</div>

packages/devtools-a11y/src/core/components/Shell.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export function Shell() {
3939

4040
<Show when={allyResult.state === 'done' && filteredIssues()}>
4141
<span class={styles().headerSub}>
42-
{`${allyResult.audit?.issues.length} issue${allyResult.audit?.issues.length !== 1 ? 's' : ''}`}
42+
{`${filteredIssues().length} issue${filteredIssues().length !== 1 ? 's' : ''}`}
4343
</span>
4444
</Show>
4545
</div>

packages/devtools-a11y/src/core/utils/ally-audit.utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ const RULE_SET_CONFIGS: Record<RuleSetPreset, Partial<RunOptions>> = {
7676
/**
7777
* Check if an impact level meets or exceeds the threshold
7878
*/
79-
function meetsThreshold(
79+
export function meetsThreshold(
8080
impact: SeverityThreshold | null | undefined,
8181
threshold: SeverityThreshold,
8282
): boolean {
@@ -268,7 +268,7 @@ export async function runAudit(
268268
? document.querySelector(context) || document
269269
: context
270270

271-
const customIssues = runCustomRules(contextElement, customRulesConfig)
271+
const customIssues = runCustomRules(contextElement, customRulesConfig, threshold)
272272

273273
// Merge all issues
274274
const allIssues = [...axeIssues, ...customIssues]

packages/devtools-a11y/src/core/utils/custom-audit.utils.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
*/
99

1010
import type { A11yIssue, CustomRulesConfig } from '../types/types'
11+
import type { SeverityThreshold } from '../types/types'
12+
import { meetsThreshold } from './ally-audit.utils'
1113

1214
/**
1315
* Interactive HTML elements that can receive focus and have implicit roles
@@ -332,6 +334,7 @@ function getSelector(element: Element): string {
332334
*/
333335
function checkClickHandlerOnNonInteractive(
334336
context: Document | Element = document,
337+
threshold: SeverityThreshold = 'serious',
335338
): Array<A11yIssue> {
336339
const issues: Array<A11yIssue> = []
337340
const timestamp = Date.now()
@@ -385,7 +388,7 @@ function checkClickHandlerOnNonInteractive(
385388
html: element.outerHTML.slice(0, 200),
386389
},
387390
],
388-
meetsThreshold: true,
391+
meetsThreshold: meetsThreshold('serious', threshold),
389392
timestamp,
390393
})
391394
} else if (hasFocus && !hasKeyboard) {
@@ -407,7 +410,7 @@ function checkClickHandlerOnNonInteractive(
407410
html: element.outerHTML.slice(0, 200),
408411
},
409412
],
410-
meetsThreshold: true,
413+
meetsThreshold: meetsThreshold('moderate', threshold),
411414
timestamp,
412415
})
413416
}
@@ -424,9 +427,12 @@ function checkClickHandlerOnNonInteractive(
424427
*/
425428
function checkMouseOnlyEvents(
426429
context: Document | Element = document,
430+
threshold: SeverityThreshold = 'serious',
427431
): Array<A11yIssue> {
428432
const issues: Array<A11yIssue> = []
429433
const timestamp = Date.now()
434+
// default threshold will be provided by runCustomRules
435+
// We'll accept threshold by adding a parameter in the function signature
430436

431437
// Build selector for elements with mouse events
432438
const mouseEventSelectors = MOUSE_ONLY_EVENTS.map(
@@ -473,7 +479,7 @@ function checkMouseOnlyEvents(
473479
html: element.outerHTML.slice(0, 200),
474480
},
475481
],
476-
meetsThreshold: true,
482+
meetsThreshold: meetsThreshold('serious', threshold),
477483
timestamp,
478484
})
479485
}
@@ -489,6 +495,7 @@ function checkMouseOnlyEvents(
489495
*/
490496
function checkStaticElementInteraction(
491497
context: Document | Element = document,
498+
threshold: SeverityThreshold = 'serious',
492499
): Array<A11yIssue> {
493500
const issues: Array<A11yIssue> = []
494501
const timestamp = Date.now()
@@ -533,7 +540,7 @@ function checkStaticElementInteraction(
533540
html: element.outerHTML.slice(0, 200),
534541
},
535542
],
536-
meetsThreshold: true,
543+
meetsThreshold: meetsThreshold('serious', threshold),
537544
timestamp,
538545
})
539546
}
@@ -562,7 +569,7 @@ function checkStaticElementInteraction(
562569
html: element.outerHTML.slice(0, 200),
563570
},
564571
],
565-
meetsThreshold: true,
572+
meetsThreshold: meetsThreshold('moderate', threshold),
566573
timestamp,
567574
})
568575
}
@@ -577,6 +584,7 @@ function checkStaticElementInteraction(
577584
export function runCustomRules(
578585
context: Document | Element = document,
579586
config: CustomRulesConfig = {},
587+
threshold: SeverityThreshold = 'serious',
580588
): Array<A11yIssue> {
581589
const {
582590
clickHandlerOnNonInteractive = true,
@@ -587,15 +595,15 @@ export function runCustomRules(
587595
const issues: Array<A11yIssue> = []
588596

589597
if (clickHandlerOnNonInteractive) {
590-
issues.push(...checkClickHandlerOnNonInteractive(context))
598+
issues.push(...checkClickHandlerOnNonInteractive(context, threshold))
591599
}
592600

593601
if (mouseOnlyEventHandlers) {
594-
issues.push(...checkMouseOnlyEvents(context))
602+
issues.push(...checkMouseOnlyEvents(context, threshold))
595603
}
596604

597605
if (staticElementInteraction) {
598-
issues.push(...checkStaticElementInteraction(context))
606+
issues.push(...checkStaticElementInteraction(context, threshold))
599607
}
600608

601609
return issues

0 commit comments

Comments
 (0)